具有多个引用的实体框架 LoadProperty
使用实体框架,您可以执行类似的操作来通过查询加载多个引用的对象。
var Customer = context.Customers.Include(x=>x.Orders.Select(y=>y.Items));
我似乎无法使用 LoadProperty 方法做同样的事情。当我已经有一个对象并且需要加载一些参考数据时,我使用 LoadProperty。
context.LoadProperty(Customer, x=>x.Orders);
那行得通。但这会引发错误..
context.LoadProperty(Customer, x=>x.Orders.Select(y=>y.Items));
这也是...
context.LoadProperty(Customer.Orders, x=>x.Items);
这是两种情况的例外...
选择器表达式 LoadProperty 必须是 MemberAccess 对于财产。
With entity framework you can do something like this to load objects for multiple references with a query.
var Customer = context.Customers.Include(x=>x.Orders.Select(y=>y.Items));
It doesn't seem like I can do the same thing with the LoadProperty method. When I already have an object and I need to load some reference data I use LoadProperty.
context.LoadProperty(Customer, x=>x.Orders);
That works. But this throws an error..
context.LoadProperty(Customer, x=>x.Orders.Select(y=>y.Items));
And so does this...
context.LoadProperty(Customer.Orders, x=>x.Items);
This is the exception for both cases...
The selector expression for
LoadProperty must be a MemberAccess
for the property.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有
LoadProperty
不允许这样做。您可以尝试使用No
LoadProperty
doesn't allow that. You can try to use approach described in another question.我遇到了同样的问题,最终循环遍历实体并一一加载它们:
I had the same problem and ended up looping through the entities and loading them one by one: