我的 EF Core 应用程序使用旨在通过允许在运行时指定导航属性加载来支持灵活的实体查询的设计模式。这个模式有 3 个关键元素:
public delegate IIncludableQueryable<T, object> IncludeClause<T>(IQueryable<T> value);
public static IncludeClause<Blog> BlogFull => entities =>
entities
.Include(e => e.Author)
.Include(e => e.Posts)
.ThenInclude(e => e.Comments);
public async Task<Blog> GetBlog(int id, IncludeClause<Blog> include)
{
return await include(_context.Set<Blog>()).FirstAsync(blog => blog.Id == id);
}
上述模式运行良好,但现在我正在寻找一种方法来以编程方式分解任何预定义的包含子句,以确定它引用的实体类型集。
在上面的例子中,我期望这个分解的结果是一个类型数组,像这样:
new[] { typeof(Blog), typeof(Author), typeof(Post), typeof(Comment), }
任何人都可以建议如何解析上面的
BlogFull
表达式树以确定它引用的实体类型吗?