【发布时间】:2015-10-05 21:31:40
【问题描述】:
我的以下实体框架语句一直在正常工作。
CostingEvent targetEvent = repository.Query<CostingEvent>()
.FirstOrDefault(ce => ce.Id == targetId);
但是,我需要禁用此代码的延迟加载,因此我在前面的语句中添加了 Include() 元素:
CostingEvent targetEvent = repository.Query<CostingEvent>()
.Include(ce => ce.ProposalSection.Proposal.Costing)
.FirstOrDefault(ce => ce.Id == targetId);
但是,这会产生运行时异常:
指定的包含路径无效。 EntityType 'Leo.Domain.CostingEvent' 没有声明名为 'Costing' 的导航属性。
我真的不明白这个错误。首先,我没有引用CostingEvent.Costing,我引用的是CostingEvent.ProposalSection.Proposal.Costing。此外,这些都是显示在 Intellisense 中的有效导航属性。
注意:这是一个数据库优先的应用程序。另请注意:repository 是一个包装类,但 Include() 引用是标准实体框架。
【问题讨论】:
-
我假设所有属性都已映射?
-
您能否提供相应课程的要点?这应该可以正常工作。
标签: c# .net entity-framework