I'm using database-first approach with Oracle database. In database I have 3 tables: USERS, ROLES, and join table between them: USERS_ROLES_ASSOCIATION. My model consists of two classes:
[Table("USERS", Schema = "SIGNUM")]
public class User
{
public User()
{
Roles = new HashSet<Role>();
}
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
[Column("USR_ID")]
public decimal UserId { get; set; }
[Column("USR_LOGIN")]
public string Login { get; set; }
[Column("USR_PASS")]
public string Password { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
[Table("ROLES", Schema = "SIGNUM")]
public class Role
{
public Role()
{
Users = new HashSet<User>();
}
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
[Column("ROL_ID")]
public decimal RoleId { get; set; }
[Column("ROL_NAME")]
public string RoleName { get; set; }
public virtual ICollection<User> Users { get; set; }
}
When I try to resolve user's roles:
using (var dbContext = new AppDbContext())
{
User user = dbContext.Users.FirstOrDefault(u => string.Equals(u.Login, "someusername"));
var roles = user.Roles.Select(r => r.RoleName); // exception
}
... I get the following error: "ORA-00942: table or view does not exist".
The problem is that EF is looking for table "dbo"."RoleUsers" instead of "SIGNUM"."USERS_ROLES_ASSOCIATION". How can I specify join table name for many-to-many relationship and schema name in database-first approach?