使用Entity Framework 6(尤其是)加载实体时,包含两级嵌套属性的语法是什么。中级是可以枚举的?
请考虑以下示例。
class Foo
{
..
public virtual ICollection<Bar> Bars { get; set; }
}
class Bar
{
...
public Gaz Gaz { get; set; }
}
class Repo
{
public async Task<IEnumerable<Foo>> GetFoosAsync()
{
var foos = await context
.Foos
.Include(foo => foo.Bars)
/* .Include("Bars/Gaz") // here I would like to include
the Gaz's in each Bar as well. Is this the right syntax?
Is there also a Expression<Func<>> syntax so I can strongly type
this? Because I can't do Include(foo => foo.Bars.Gaz) because
Bars is an IEnumerable<T> */
.ToListAsync();
return foos;
}
}
我正在使用面向.NET Framework 4.6.1的Entity Framework 6.2.0。