好的,所以根据this page,实体框架应该通过在Include
方法中使用Select
来加载多个级别。实体框架急切加载多级异常
我有以下代码:
var reports = _context.Reports
.Include(rt => rt.Fields)
.Include(rt => rt.Fields.Select(f => f.FieldType))
.Include(rt => rt.Fields.Select(f => f.FieldType.FieldIdentifier));
然而,这将引发InvalidOperationException
- “无效型表达的”关于该呼叫到第二包含。异常来自EntityFrameworkHelper.CollectRelationalMemebers
。
我也尝试使用字符串Include
相关的属性,但也失败了(我宁愿避免使用字符串,如果可能的话)。
我为.NET 4.0使用EF 5.0 DLL。我的EF课程是老式的数据库第一EntityObject
s。
有谁知道原因,如果有什么我可以做这个异常?
编辑:
当使用字符串版本:
var reports = _context.Reports
.Include("Fields")
.Include("Fields.FieldType")
.Include("Fields.FieldType.FieldIdentifier"));
它抛出InvalidOperationException
- 无效类型的表达式。
当您使用基于字符串的Include版本时,确切的异常信息是什么? – Slauma 2013-02-20 20:00:40
见上面的答案。 – MgSam 2013-02-20 20:20:18
我的意思是基于**字符串的** Include版本的例外情况。 – Slauma 2013-02-20 20:39:04