【发布时间】:2017-01-15 11:20:30
【问题描述】:
This is the structure of the database on which i am working.Click on this text.
我想选择属于特定 CategoryID 的用户的 EmailID MailStatusTable 中提到的 MailStatus 列包含 False。
这是我目前得到的查询:
var category = from m in mcontext.MailStatusTable
where m.MailStatus == false
select new
{
CategoryID = m.CategoryID
};
var email_list = from u in mcontext.UserProfiles
where u.AnExpert == true
where u.AnInstitute == true
where category.Contains(u.UserProfileID)
select new
{
LastName = u.LastName,
EmailU = u.Email
};
但我的第三个 where 条件不正确,因为 UserProfiles 表和类别表都通过第三个表连接,并且该表没有模型类,因为其中的两个列都是外键。
这是我在上下文类中定义的关系:
modelBuilder.Entity<Categories>()
.HasMany(c => c.CategoriesUserProfile).WithMany(x => x.UserProfileCategories).Map(q => q.MapLeftKey("CategoryID").MapRightKey("UserProfileID").ToTable("UserProfileCategories"));
我应该如何选择属于特定类别的用户的 EmailID。
提前致谢。 当然, 这些是我的模型:
public class UserProfiles
{
public int UserProfileID { get; set; }
public string LastName { get; set; }
public bool AnExpert { get; set; }
public bool AnInstitute { get; set; }
public bool Client { get; set; }
public string Email { get; set; }
public virtual ICollection<Categories> UserProfileCategories{get;set;}
}
public class Categories
{
public int CategoryID { get; set; }
public String Name { get; set; }
public virtual ICollection<UserProfiles> CategoriesUserProfile { get; set; }
public virtual ICollection<MailStatusTables> CategoriesMailStatusTable { get; set; }
}
public class MailStatusTables
{
public int MailStatusID { get; set; }
public bool MailStatus { get; set; }
public int EnquiryID { get; set; }
public int CategoryID { get; set; }
public virtual Categories MailStatusCategory { get; set; }
}
【问题讨论】:
-
你能发布你的模型吗?
标签: c# asp.net-mvc linq junction-table