1

我想在数据库中为某些实体创建一个特定的模式。“Role”和“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");
    }
}

但是,当 DB 生成时,我看到在 ACL 模式中生成的角色和系统密钥以及在 dbo 模式中创建的联结表(SystemKeyRole)。我如何强制 SystemKeyRole(junction table) 在“ACL”模式中生成?

4

1 回答 1

2

您可以通过添加如下配置来做到这一点:

modelBuilder.Entity<Role>()
    .HasMany(p => p.SystemKeys)
    .WithMany(p => p.Roles)
    .Map(p => p.ToTable("SystemKeyRole", "ACL"));
于 2013-09-15T15:56:01.553 回答