Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd like to know the proper EntityFramework design for the following common scenario:
I have a User Search page with search fields for FirstName, LastName, EMail and RoleId.
I have auto-genned the edmx model using the standard wizard in VS2010.
The underlying data model has a many-to-many relationship between User and Role in a UserRole table.
Searching on first name, last name and email is easy:
return context.Users.Where(
x => x.FirstName == (request.FirstName ?? x.FirstName) &&
x.LastName == (request.LastName ?? x.LastName) &&
x.EMail == (request.EMail ?? x.EMail)
However, I'm trying to figure out the best way to include role ID in the UserRole table in the search. The following statement is invalid but you should be able to see what I'm trying to do here:
return context.Users.Where(
x => x.FirstName == (request.FirstName ?? x.FirstName) &&
x.LastName == (request.LastName ?? x.LastName) &&
x.EMail == (request.EMail ?? x.EMail) &&
x.UserRoles.Where(y => y.RoleId == (request.RoleId ?? y.RoleId)));
So can you please show me the correct way to include RoleId in my user search? Thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900