动态EF核心包含等效于ThenInclude

时间:2018-05-21 17:15:48

标签: c# entity-framework

在ef核心上,我们可以使用..

加载图表
DbContext.Player
.Include(a => a.Phones)
.Include(a => a.Addresses).ThenInclude(s => s.StateProvince).ThenInclude(c => c.CountryRegion)
.Include(a => a.EmailAddresses)

我正在尝试按如下方式构建动态图表。

var expression = "Phones;Addresses,EmailAddresses";

 var includes = expression.Split(';', StringSplitOptions.RemoveEmptyEntries);

 var q = DbContext.Set<Player>().AsQueryable();

 foreach (var include in includes)
     q = q.Include(include);

但我不能包含Address子相关实体,例如StateProvince和CountryRegion,因为我没有ThenInclude构造。

如何使用ef core动态包含子相关实体?

0 个答案:

没有答案