I have 3 tables that need to be mapped to the Entity Framework, and I'm not sure how to do this correctly. Here are my 3 entities:
public class User { [Key] public int user_id {get; set;} public string user_name {get; set;} public virtual List<Role> roles {get; set;} } public class Role { [Key] public int role_id {get; set;} public string role_name {get; set;} } public class User_Role { [Key] public int user_role_id {get; set;} public int user_id {get; set;} public int role_id {get; set;} }
Note that the User_Role object is simply a lookup table to associate many roles with one user.
With SQL, I would just do something like:
SELECT User.user_name, Role.role_name FROM User INNER JOIN User_Role ON User_Role.user_id = User.user_id INNER JOIN Role ON Role.role_id = User_Role.role_id WHERE User.user_id = 123
I'm relatively new to the Entity Framework, so I'm not sure if this is the best way to handle this using the EF4 DbContext (and maybe the Fluent API?), But I hope it will be pretty simple.
Thanks in advance.
inner-join mapping entity-framework lookup entity-framework-4
chrisg229
source share