This is the structure of the database on which i am working.Click on this text.はasp.netのMVCでは、多くの関係に
を多く使用してデータベースからレコードを取得する私は、列MailStatusがFalse含まれMailStatusTableで述べた特定の区分 に属するユーザーのEMAILIDを選択します。
これは私がこれまで持っているクエリです:
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
};
しかし、私の第三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; }
}
あなたのモデルを投稿できますか? –