关于Lambda

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中

原文地址:https://www.cnblogs.com/jiajinyi/p/3339998.html