0

这是示例模型类,与 Entity Framework Code First 一起使用:

public class Master
{
  public int Id { get; set; }
  public Collection<Detail> Details { get; set; }
}

public class Detail
{
  public int Id { get; set; }
  public Master Master { get; set; }
  public SubDetail SubDetail1 { get; set; }
  public SubDetail SubDetail2 { get; set; }
}

public class SubDetail
{
  public int Id { get; set; }
}

我想Master明确加载它的所有细节和子细节。要加载我正在使用的详细信息Include

context.Masters.Include("Details").Where(master => master.Id == 1);

我应该使用什么来加载子详细信息?

4

1 回答 1

1

尝试

context.Masters.Include(m => m.Details.Select(d => d.SubDetail1))
   .Include(m => m.Details.Select(d => d.SubDetail2))
   .Where(master => master.Id == 1);

非通用版本

context.Masters.Include("Details.SubDetail1")
   .Include("Details.SubDetail2")
   .Where(master => master.Id == 1);
于 2012-06-26T09:43:24.897 回答