Hi,
I'm trying to understand some fundamental best practices using Entity Framework.
My EDM design has Group and User entities which the Group may contain users and other groups.
The question is:
What is the best way to retrieve the users from a group?
For getting the groups its easy, just creating the context object and creating a list from the groups table.
But when I want the see the users within a group, the context is closed (as it should be).
I thought about two approaches:
1) sending the group back, attaching it to context and use the Load() method on the Users and return the List of Users.
Here I don't know when to attach and when I shouldn't and when the EDM will grow I will have to do a lot back and forth for each reference to load
2) linq query from the user side.
from u in context.Users where u.Groups.Contains(group) select u
Here I'm getting an exception that only primitive types can be used.
So what is the the right way to do so?
Thanks Ronny