我有三个实体,比如Parent,Child&孙子辈。这个GrandChild有三个名单(a,b& c)。
如何使用" Include"来检索所有这些列表。在实体框架中?
我可以像这样回复一个列表:Include(" Parent.Child.GrandChild.a"),
但是当我添加另一个Include如:Include(" Parent.Child.GrandChild.b")时,会抛出错误。
我将如何在单个查询中检索所有这些列表?
我的代码如下:
objUserNew = objContaxt.ContextRegistration
.Include("listing.postlist.commentslist")
.Include("listing.postlist.taglist")
.Include("listing.postlist.knocklist")
.FirstOrDefault(x => x.id == objUser.id);
public class registration
{
public int id { get; set; }
public string firstname { get; set; }
public forgtPass forgtPass { get; set; }
public List<listing> listing { get; set; }
}
public class listing
{
public int id { get; set; }
public string address { get; set; }
public List<post> postlist { get; set; }
}
public class post
{
public int id { get; set; }
public string imgUrl { get; set; }
public List<tag> taglist { get; set; }
public List<comments> commentslist { get; set; }
public List<knoqs> knoqs { get; set; }
}
public class tag
{
public string name { get; set; }
}
public class comments
{
public int id { get; set; }
public string comment { get; set; }
public status status { get; set; }
}
public class knoqs
{
public int id { get; set; }
public virtual int registration_id { get; set; }
[ForeignKey("registration_id")] public registration registration { get; set; }
public status status { get; set; }
}