[英]EF many-to-many relationship with specific scheam
我想在DB中為某些實體創建特定的架構。 “角色”和“ SystemKey”具有多對多關系,並且兩個主題均處於“ ACL”架構中。
public class Role
{
public long Id { get; set; }
public string Title { get; set; }
//Navigation prop
public virtual ICollection<SystemKey> SystemKeys { get; set; }
}
和
public class SystemKey
{
public SystemKey()
{
Roles = new HashSet<Role>();
}
public long Id { get; set; }
public string ActionName { get; set; }
public string ControllerName { get; set; }
//Navigation prop
public ICollection<Role> Roles { get; set; }
}
並在“ OnModelCreating”中定義:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Role>().ToTable("Role", "ACL");
modelBuilder.Entity<SystemKey>().ToTable("SystemKey", "ACL");
}
}
但是,當生成數據庫時,我看到了在ACL模式中生成的角色和系統密鑰以及在dbo模式中創建的聯結表(SystemKeyRole)。 如何強制SystemKeyRole(連接表)在“ ACL”架構中生成?
您可以通過添加如下配置來做到這一點:
modelBuilder.Entity<Role>()
.HasMany(p => p.SystemKeys)
.WithMany(p => p.Roles)
.Map(p => p.ToTable("SystemKeyRole", "ACL"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.