Let's say we have User, Line Of Business (LOB) and Role. User have 1 LOB. But a user can also have number of roles within different LOBs.
The Code First model below creates 3 tables USERS, ROLES and LOBS. If left to his own devices it also creates UserRoles. Which is not what I want.
So far I've tried creating UserLOBRole {RoleId, UserId, LOBCode} object and marked all fields as composite primary, however EF barks about foreign key.
Is there any way I can describe such relationships in EF 4.1 code first?
Any help is greatly appreciated.
public class User
{
public int UserId {get;set;}
public string UserName {get;set;}
public virtual LOB UserLOB {get;set;}
// HOW DO I DEFINE RELATIONSHIP HERE?
public virtual ICollection<Role> UserRoles {get;set;}
}
public class Role
{
public int RoleId {get;set;}
public string RoleName {get;set;}
}
public class LOB
{
public string LOBCode {get;set;}
public string LobName {get;set;}
}