C# 使用lambda从孙子实体检索多个列表

C# 使用lambda从孙子实体检索多个列表,c#,asp.net-mvc-4,lambda,C#,Asp.net Mvc 4,Lambda,我有三个实体,比如父母、孩子和孙子。这个孙子有三张名单(a、b和c) 如何在实体框架中使用“包含”检索所有这些列表 我可以检索这样一个列表:Include(“Parent.Child.sunder.a”) 但当我添加另一个Include时,比如:Include(“Parent.Child.grant.b”),它抛出了一个错误 如何在一个查询中检索所有这些列表 我的代码如下: objUserNew = objContaxt.ContextRegistration .Inc

我有三个实体,比如父母、孩子和孙子。这个孙子有三张名单(a、b和c)

如何在实体框架中使用“包含”检索所有这些列表

我可以检索这样一个列表:Include(“Parent.Child.sunder.a”)

但当我添加另一个Include时,比如:Include(“Parent.Child.grant.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; }
}

objUserNew=objContaxt.ContextRegistration
.Include(“listing.postlist.commentslist”)
.包括(‌​“listing.postlist.taglist”)
.Include(“listing.postlist.knocklist”)
.第一道防线(‌​x=>x.id==objUser.id);
公开课注册
{
公共int id{get;set;}
公共字符串名{get;set;}
公共forgtPass forgtPass{get;set;}
公共列表列表{get;set;}
}
公共类列表
{
公共int id{get;set;}
公共字符串地址{get;set;}
公共列表postlist{get;set;}
}
公营职位
{
公共int id{get;set;}
公共字符串imgUrl{get;set;}
公共列表标记列表{get;set;}
公共列表注释列表{get;set;}
公共列表旋钮{get;set;}
}
公共类标签
{
公共字符串名称{get;set;}
}
公开课评论
{
公共int id{get;set;}
公共字符串注释{get;set;}
公共状态状态{get;set;}
}
公共类旋钮
{
公共int id{get;set;}
公共虚拟整数注册\u id{get;set;}
[ForeignKey(“registration_id”)]公共注册注册{get;set;}
公共状态状态{get;set;}
}

请显示您的代码,以便我们重现问题并为您提供更多帮助。objUserNew=objContaxt.ContextRegistration.Include(“listing.postlist.commentslist”).Include(“listing.postlist.taglist”).Include(“listing.postlist.knocklist”).FirstOrDefault(x=>x.id==objUser.id);公共类注册{public int id{get;set;}public string firstname{get;set;}public forgtPass forgtPass{get;set;}公共列表列表{get;set;}公共类列表{public int id{get;set;}公共字符串地址{get;set;}公共列表postlist{get;set;}}您应该使用问题下方的“编辑”按钮编辑问题,而不是用注释显示代码。