如何在EF Core中为Openiddict-core表设置默认方案

时间:2019-02-08 09:59:42

标签: openiddict

如何为Openiddict-core表设置默认方案?

不幸的是,EF Core没有(不是我所知道的)仅接受方案的方法,并且(EntityTypeBuilder.ToTable)在方案旁边还需要表名。

1 个答案:

答案 0 :(得分:1)

没有特定于OpenIddict的东西可以处理,但是使用常规的EF钩子可以轻松实现。这是一个示例:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions options)
        : base(options) { }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);

        foreach (var entity in builder.Model.GetEntityTypes())
        {
            for (var type = entity; type != null; type = type.BaseType)
            {
                if (type.ClrType.Assembly == typeof(OpenIddictApplication).Assembly)
                {
                    entity.SqlServer().Schema = "security";

                    break;
                }
            }
        }
    }
}