views:

40

answers:

2
public List<Store> GetAllFriendsTopStores(long uid, List<long> users)
{
    using (var entities = new myEntities()) {
        var v = entities.DbUsers
            .Where( x => users.Contains( x.uid ))
            .Stores // i can't select stores here?  Why is this???
    }
}

In this case Stores is a navigation property... I need to be able to access the stores objects for my friends in this scenerio.

+1  A: 

After Where you have IEnumerable collection, so if you have only one user as the result and want to access it - apply Single()

    var v = entities.DbUsers
        .Where( x => users.Contains( x.uid ))
        .Single()
        .Stores;

UPD:

    var v = entities.DbUsers
        .Where( x => users.Contains( x.uid ))
        .Select( x => x.Stores );

In this case you will get the collection of users' Stores.

UPD 2:

    var v = entities.DbUsers
        .Where( x => users.Contains( x.uid ))
        .Select( x => new { Stores = x.Stores, BllStore = new BllStore{a=x.a} );

If I understand you correctly - that is what you are looking for. After this you have the collection with anonymous objects, each of which has Stores and BllStore property.

zerkms
your way does work... but what im trying to do is get a list of users, and then return the stores for all of them... is this possible?
wcpro
yes, i've added an update
zerkms
lets say i wanted to do a select statement like x=>new BllStore{a=x.a} something like thiat, would i add a second select statement or is there a way to do it all in 1 statement.
wcpro
I've added another update
zerkms
A: 

At the place you are attempting to use Stores, you are trying to call it on a filtered sequence (collection) of DbUser objects. You'd need to be in a context that gives you access to a single record to use that.

Andrew Barber
i understand now... is there any way to accomplish what I'm trying to do with a single statement?
wcpro