1. 查询时,包含关联子对象。如:

  数据库中包含表Father和Son,映射实体如下:

public class Father
{
    public string Name{get;set;}
    public string SonId{get;set;}
    public Son Son{get;set;}
}
public class Son { public string SonId{get;set;} public string Name{get;set;} public int Age{get;set;} }

  如果在查询Father的时候想包含子对象Son,语法为:

  List<Father> fatherSet = _context.Father.Where(f=>f.Name=="xxx").Include(f=>f.Son).ToList();

  注意:Include方法包含在命名空间System.Data.Entity中

 

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2022-01-17
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
猜你喜欢
  • 2021-12-15
  • 2021-09-06
  • 2021-06-27
  • 2022-12-23
  • 2021-10-03
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案