简体   繁体   English

一对多和一对多关系

[英]One-to-many and one-to-many relationship

I have this one-to-many and one-to-many relationship with entity framework and I had a hard time retrieving it using eager loading, this is the sample: 我与实体框架具有一对多和一对多的关系,我很难用急切的加载来检索它,这是示例:

User has one to many relationship with Classmates which has one to many relationship with Items . 用户同学具有一对多的关系,而同学项目具有一对多的关系。

I'm trying to retrieve it as: 我正在尝试将其检索为:

context.User.Include("Classmates").Include("Items").SingleOrDefault(n => n.username == "test");

But it issues and exception, I'am using entity framework 4.0 (ObjectContext). 但是它存在问题和例外,我正在使用实体框架4.0(ObjectContext)。 Thank you in advance guys! 预先谢谢你们!

Edit: 编辑:

The exception is A specified Include path is not valid. 例外是指定的包含路径无效。 The EntityType 'User' does not declare a navigation property with the name 'Items'. EntityType“用户”未声明名称为“项目”的导航属性。

I've already found the answer here, sorry because I never heard of the term "Eager loading on multiple levels". 很抱歉,我已经在这里找到了答案,因为我从未听说过“在多个级别上快速加载”一词。

Here is the solution: 解决方法如下:

context.User.Include("Classmates.Items").SingleOrDefault(n => n.username == "test");

Here is the link for more articles regarding this problem: 这是有关此问题的更多文章的链接:

http://msdn.microsoft.com/en-us/data/jj574232.aspx http://msdn.microsoft.com/en-us/data/jj574232.aspx

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

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