简体   繁体   English

EF未实现父对象

[英]EF not materializing the parent objects

I have a strange behavior I never came across while working with EF and SqlServer. 我有一个奇怪的行为,在使用EF和SqlServer时从未遇到过。 I have a Book_Cart that has some related entities like in the picture. 我有一个Book_Cart,它具有图片中的一些相关实体。 lazy loading is turned On 延迟加载已开启

在此处输入图片说明

The funny thing that happens is that the Child records are loaded and executed, while the parent objects are not. 有趣的是,子级记录已加载并执行,而父级对象未加载。 While debugging, the Book_Cart entity gets loaded, and all of the attributes, but the parent entities are not. 在调试时,将加载Book_Cart实体以及所有属性,但不会加载父实体。

This was working all of the time, and I had one change done, adding the Transaction table and refreshing the model. 这一直在起作用,我做了一个更改,添加了Transaction表并刷新了模型。 Since then I am experiencing the error on the relations that have not been touched. 从那时起,我就遇到了未曾触及的关系错误。

I have tried removing the entities from the model, the relations and related objects, but nothing works. 我尝试从模型,关系和相关对象中删除实体,但是没有任何效果。 Tried the whole "clean-rebuild-close" Visual studio process, but noting changes. 尝试了整个“ clean-rebuild-close” Visual Studio流程,但注意了更改。

Any suggestions? 有什么建议么?

I solved it. 我解决了 I cannot believe what happened. 我不敢相信发生了什么。

The context did not lazyLoad the parent records, although it was set to true. 尽管上下文设置为true,但并未lazyLoad父记录。 After 6 hours of headbanging I tried (out of desperation) to set it to false and back to true, and it started to work. 经过六个小时的猛烈撞击,我尝试(出于绝望)将其设置为false并恢复为true,然后它开始工作。

I tried everything, .... restart VS, Windows, revert from GIT and everything that came to my mind, but after 6 hours, LazyLoading property of the Model needed to be set to false, and to true again. 我尝试了所有方法,....重新启动VS,Windows,从GIT还原,然后想到了所有方法,但是6个小时后,需要将Model的LazyLoading属性设置为false,然后再次设置为true。

Never heard or experienced this before. 以前从未听说过或经历过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM