This is the structure of the database on which i am working.Click on this text.
I want to select the EmailID of the users which belong to a particular CategoryID mentioned in MailStatusTable where the column MailStatus Contains False.
This is the query which i have got so far :
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
};
But my third where condition is incorrect as both the UserProfiles Table and Category Table are connected via a Third Table and that table doesn't have a model class as both the columns in it are foreign keys.
This is the relation which i have defined in my context class :
modelBuilder.Entity<Categories>()
.HasMany(c => c.CategoriesUserProfile).WithMany(x => x.UserProfileCategories).Map(q => q.MapLeftKey("CategoryID").MapRightKey("UserProfileID").ToTable("UserProfileCategories"));
How Should i pick the EmailID of the users which Belong to a particular category.
Thanks in advance. Sure, These are my models :
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; }
}