装载在linq2entities自动关系 [英] Loading relations in linq2entities automatically
问题描述
当我在我的模型两个实体之间的关系:
When i have a relation between two entities in my model:
[GroupMember](*)-----(1)[用户]
[GroupMember] (*) ----- (1) [User]
和试图从这种关系与LINQ选择项目:
and tries to select items from this relation with LINQ:
从_user.GroupMember选择实体实体
From entity in _user.GroupMember select entity
我总是得到一个空的结果,除非我用下面的语句先加载的关系:
I always get an empty result unless I load the relation first with following statement:
_user.GroupMember.Load()
_user.GroupMember.Load()
有没有一种方法,以避免加载关系也是这样吗?
Is there a way to avoid loading the relations like this?
推荐答案
如果你有级联关系,你可以处理他们与 .INCLUDE(GroupMember.AnotherTable.YetAnotherTable)
这是不是有做链接包括呼叫更好一点。
If you have cascading relations, you can handle them with .Include("GroupMember.AnotherTable.YetAnotherTable")
which is a little nicer than having to do chained Include calls.
这篇关于装载在linq2entities自动关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!