Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 Entity Framework many-to-many custom join table name and schema name
    text
    copied!<p>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:</p> <pre><code>[Table("USERS", Schema = "SIGNUM")] public class User { public User() { Roles = new HashSet&lt;Role&gt;(); } [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&lt;Role&gt; Roles { get; set; } } [Table("ROLES", Schema = "SIGNUM")] public class Role { public Role() { Users = new HashSet&lt;User&gt;(); } [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] [Column("ROL_ID")] public decimal RoleId { get; set; } [Column("ROL_NAME")] public string RoleName { get; set; } public virtual ICollection&lt;User&gt; Users { get; set; } } </code></pre> <p>When I try to resolve user's roles:</p> <pre><code>using (var dbContext = new AppDbContext()) { User user = dbContext.Users.FirstOrDefault(u =&gt; string.Equals(u.Login, "someusername")); var roles = user.Roles.Select(r =&gt; r.RoleName); // exception } </code></pre> <p>... I get the following error: "ORA-00942: table or view does not exist".</p> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload