实体框架&包括 [英] Entity Framework & Include
本文介绍了实体框架&包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有
请帮助我在以下情况下使include()工作:
All Please help me make include() work in the following case:
ctx.Messages
.Include("Comments.CommentType")
.Include("Comments.Owner")
.Include("Comments.Message")
.Where(m => m.RID == messageId)
.SelectMany(m => m.Comments)
.Where(c => c.CommentType.Id == commentTypeId)
.ToList();
如何重写此查询?
PS我使用EF 3.5(不是4.0)
P.S. I'm using EF 3.5 (not 4.0)
推荐答案
这很可能与问题包含并加入。基本上归结为:包含仅在语句结尾处应用,并且由于加入,您的查询类型从 IQueryable< Message>
更改为的IQueryable<注释>
。
This is most likely related to an issue with Include and joins. Basically it comes down to this: Includes are only applied at the end of the statement, and due to joining, the type of your query changes from an IQueryable<Message>
to an IQueryable<Comment>
.
通过删除连接,它应该正确地包含导航属性。尝试以下内容:
By removing the join, it should correctly include the navigation properties. Try the following:
ctx.Comments
.Include("CommentType")
.Include("Owner")
.Include("Message")
.Where(c => c.Message.RID == messageId && c => c.CommentType.Id == commentTypeId)
.ToList();
这篇关于实体框架&包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文