如何为多对多关系表指定架构? [英] How to specify a schema for a many-to-many relationship table?
问题描述
我有一个用户角色多对多关系,这是由 EntityTypeConfiguration< Role>
派生类中的这段摘录指定的,可以让我为单个表格指定模式,例如:
I have a User-Role many-to-many relationship, specified by this excerpt from an EntityTypeConfiguration<Role>
derived class that allows me to specifiy schemas for single tables, e.g:
[Schema(SchemaNames.ParkPay)]
class WeekDayConfig : EntityTypeConfigurationWithSchema<WeekDay>
{
internal WeekDayConfig()
{
Ignore(t => t.IsDeleted);
Property(p => p.Name)
.IsRequired()
.HasMaxLength(20);
}
}
现在,对于角色
,配置类包含此代码,结果表 UserRole
在dbo模式下创建,而不是我想要的模式。这是代码:
Now, for Role
, the configuration class contains this code, and the resultant table UserRole
gets created under the 'dbo' schema, not my desired schema. This is that 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");
});
}
}
有什么我可以做的,除了脚本一个模式在初始化的播种阶段更改,在'parkpay'模式下创建表 UserRole
而不是'dbo'模式?
Is there anything I can do, except script a schema change during the seeding phase of initialization, to have table UserRole
created under the 'parkpay' schema and not the 'dbo' schema?
推荐答案
我不明白为什么这不行:
I don't see why this wouldn't work:
public RoleConfig()
{
HasMany(t => t.Users)
.WithMany(t => t.Roles)
.Map(m =>
{
m.ToTable("UserRole","parkpay");
m.MapLeftKey("RoleId");
m.MapRightKey("UserId");
});
}
这篇关于如何为多对多关系表指定架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!