How do I specify a schema for a many-to-many relationship table?

I have a many-to-many relationship from user and role, indicated by this excerpt from the EntityTypeConfiguration<Role> derived class, which allows me to specify schemas for individual tables, for example:

 [Schema(SchemaNames.ParkPay)] class WeekDayConfig : EntityTypeConfigurationWithSchema<WeekDay> { internal WeekDayConfig() { Ignore(t => t.IsDeleted); Property(p => p.Name) .IsRequired() .HasMaxLength(20); } } 

Now, for Role , the configuration class contains this code, and the resulting UserRole table is created within the "dbo" schema, and not in my desired schema. This is the code:

 [Schema(SchemaNames.ParkPay)] internal class RoleConfig : EntityTypeConfigurationWithSchema<Role> { public RoleConfig() { HasMany(t => t.Users) .WithMany(t => t.Roles) .Map(m => { m.ToTable("UserRole"); m.MapLeftKey("RoleId"); m.MapRightKey("UserId"); }); } } 

Is there anything I can do other than a script for changing the circuit during the seed initialization phase to have a UserRole table created using the parkpay scheme, and not the dbo scheme?

+6
source share
1 answer

I do not understand why this did not work:

 public RoleConfig() { HasMany(t => t.Users) .WithMany(t => t.Roles) .Map(m => { m.ToTable("UserRole","parkpay"); m.MapLeftKey("RoleId"); m.MapRightKey("UserId"); }); } 
+10
source

Source: https://habr.com/ru/post/947318/


All Articles