问题描述
EF6具有DbSet.Include的重载,它接受一个字符串参数,该字符串参数表示以点分隔的相关对象列表,以返回查询结果。这对于在多级对象图中快速加载实体很有用。例如:
EF6 has an overload of DbSet.Include which accepts a string parameter representing a dot-separated list of related objects to return in the query results. It is useful for eager-loading entities in a multi-level object graph. For example:
var order = await _dbContext.Orders
.Include(o => o.Customer)
.Include("OrderDetails.Product") // dot-delimited path
.SingleOrDefaultAsync(o => o.OrderId == id);
这将返回两个相关的订单明细,并通过生成一条SQL语句填充每个明细的Product属性。联接OrderDetail和Product表。
This will return both related order details and populate the Product property of each detail by generating a SQL statement that joins OrderDetail and Product tables.
我正在寻找一种使用EF7的方法,但是我没有看到 DbSet.Include 的重载。 >接受 string 路径参数。 EF7是否提供与EF6 API相同的结果?
I am looking a way to do this with EF7, but I don't see an overload of DbSet.Include which accepts a string path parameter. Does EF7 provide a way to achieve the same result as the EF6 API?
PS。我只是注意到问题已打开,看来它可以解决我的问题。
PS. I just noticed issue #1151 is open, and it looks like it may address my question.
推荐答案
您正确地认为正在跟踪这种情况。还有一些设计会议记录,总结了将在EF7中使用的API-。
You are correct that #1151 is tracking this scenario. There are also some design meeting notes that summarize the API that will be available in EF7 - https://github.com/aspnet/EntityFramework/wiki/Design-Meeting-Notes:-January-8,-2015.
这篇关于DbSet.Include运算符,用于ef7接受字符串路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!