views:

119

answers:

2

When i have a relation between two entities in my model:

[GroupMember] (*) ----- (1) [User]

and tries to select items from this relation with LINQ:

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()

Is there a way to avoid loading the relations like this?

A: 

I just realized that when i load the User from the database, I can use Include to load GroupMember with the User like this:

Users=from entity in db.User.Include("GroupMember") select entity

But if I have several relations and maybe wants to access relations on the relations, this gets very ugly.

So I am still looking for a better/nicer solution to my issue.

slamidtfyn
I will accept my own answer to this, but if anyone has a prettier solution please let me know.
slamidtfyn
+1  A: 

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.

dommer