日期:2014-05-20 浏览次数:20835 次
public class Tasks { public Tasks() { this.Tags = new List<Tag>(); } public int TaskId { get; set; } public int UserId { get; set; } public string TaskName {get;set;} public virtual UserInfo UserInfo { get; set; } public virtual ICollection<Tag> Tags { get; set; } } public class Tag { public Tag() { this.Tasks = new List<Tasks>(); } public int TagId { get; set; } public int UserId { get; set; } public string TagName { get; set; } public virtual UserInfo UserInfo { get; set; } public virtual ICollection<Tasks> Tasks { get; set; } } //Mapping // Relationships this.HasMany(t => t.Tags) .WithMany(t => t.Tasks) .Map(m => { m.ToTable("TaskTag"); m.MapLeftKey("TaskId"); m.MapRightKey("TagId"); });
select tasks.* from tasks left join tasktag on tasks.taskid = tasktag.taskid left join tag on tag.tagid = TaskTag.tagid where tag.tagname='test'