views:

40

answers:

1

this is a second part to my first question posted here...

http://stackoverflow.com/questions/3757185/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.

+1  A: 

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.

Siva Gopal
this is an approach i considered, i need to be able to access the store data afterwards in its own "select" statement, like using a POCO object.. so Select(r=>r.stores) does not give taht ability to do something like r=>new Store(r.store.x),, i gues that is the question i am asking
wcpro