Reputation: 2427
this is a second part to my first question posted here...
Linq Query after Where statement not returning relationship data
What Im trying to do is use linq to represent this data...
Get My Friends' Favorite stores, where store is an object that contains a list of the friends who also have favorited each store. The relationship is basically a many to many of users and stores
I have started with a query like this...
entities.DbUsers.Where( x => users.Contains( x.uid ) )
At the end of this statement I don't have the context to access the stores objects that are attached to the friends, so i tried doing something like this...
entities.DbUsers.Where( x => users.Contains( x.uid ) ).Select( r => new Store( ) )} );
however in this case the r is a DbUesr object, so i cant really build a store object from it very easily.
Upvotes: 0
Views: 136
Reputation: 3502
You may try the following code :
Assumed that "Stores" is the Association name inside Users for Stores.
var filteredUsers = entities.DbUsers.Where( x => users.Contains( x.uid ) ).Select( r => r.Stores);
Now if you access filteredUsers then it should give you the associated stores for that user. Also make sure that Stores is not being Lazy loaded.
Upvotes: 1