nickand
nickand

Reputation: 127

Entity Framework Linq vb get list of users based on curent user account list or belong to no account

This code lists what users belong to the same accounts as the current user.

entity.users.Where(Function(b) b.accounts.Any(Function(c) c.users.Any(Function(d) d.user_id = MySession.Current.user_id))).ToList

What i cant work out, is how would i get it to return users that belong to no account groups as well as users that have the same accounts as current user?

This code is for certain admin users to only admin there own accounts and to manage new users that dont belong to an account yet.

Thanks for your time.

Upvotes: 0

Views: 149

Answers (1)

Slauma
Slauma

Reputation: 177133

I think you just have to add an ... Not b.accounts.Any() OrElse ... to the Where clause, like so:

entity.users.Where(Function(b) _
    Not b.accounts.Any() OrElse _
        b.accounts.Any(Function(c) c.users.Any(Function(d) _
            d.user_id = MySession.Current.user_id))).ToList()

Upvotes: 1

Related Questions