我正在使用带有 POCO 的 EF 4,并禁用延迟加载和代理创建(由于序列化要求)。我有两个表,它们使用第三个交叉引用表具有多对多关系。在 EF 中,交叉引用实体不存在,并且实体关系的两侧都有一对多的导航属性(如预期)。
但是,当我使用已通过 SQL Manager 查询确认具有数据的实体之一的导航属性时,我得到一个空结果集。
还有其他人遇到过这个吗?如果是这样,任何有关如何解决的建议将不胜感激。
谢谢!
I'm using EF 4 with POCO and lazy loading and proxy creation disabled (due to serialization requirements). I have two tables that have a many to many relationship using a third cross-reference table. In EF, the cross-reference entity does not exist and I have one to many navigation properties on both sides of the entity relationships (as expected).
However, when I use the naviation property of one of the entities that I have confirmed via SQL Manager queries to have data, I get an empty result set.
Has anyone else run into this? If so, any advice on how to resolve would be most appreciated.
Thanks!
发布评论
评论(2)
您需要使用 LoadProperty 或 包含方法。
更多来自 [MSDN]
“由于 POCO 实体与从 EntityObject 继承的对象没有相同的关系要求,因此加载相关对象需要稍微不同的过程”
You need to use LoadProperty or Include method.
More from [MSDN]
"Because POCO entities do not have the same relationship requirements as objects that inherit from EntityObject, a slightly different process is required to load related objects"
您不能禁用代理创建并使用延迟加载。 (请参阅 POCO 支持延迟(延迟)加载吗? @ http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part- 1-the-experience.aspx)。
代理是延迟加载工作的基础。该链接(上面)还演示了如何急切地加载相关类型,如果您关闭代理创建,您将需要执行此操作。
You cannot disable proxy creation and also use lazy loading. (See Is Deferred (Lazy) Loading supported with POCO? @ http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx).
The proxies are what make the lazy loading work. That link (above) also demonstrates how to eagerly load the related types, which you'll want to do if you keep proxy creation off.