views:

56

answers:

2

I have 2 tables (Users and Roles) they are mapped as Many-to-Many in relational db. When I imported to Entity Data Content, they are still staying as the same relationship.

Since they are mapped as Many-To-Many in Entity, I can access

Users.RoleCollection 
or
Roles.UserCollection

However, when I execute this LINQ query, I got "LINQ to Entities does not recognize the method 'Boolean Contains... method, and this method cannot be translated into a store expression."

var result (from a in Users
            from b in Roles
            where a.RoleCollection.Contains(b)
            select a);

I think I must did something wrong... please help.

+2  A: 

Just use any....

     where a.RoleCollection.Any(x=>x.ID==b.ID)

or

     where a.RoleCollection.Any(x=>x==b)
Nix
A: 

See http://stackoverflow.com/questions/374267/contains-workaround-using-linq-to-entities

Hightechrider
No, that's a different use case for `Contains` (that question uses a `List`, as opposed to part of the L2E query. @Nix is correct here.
Craig Stuntz