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

如何在EF core中为Openiddict core表设置默认方案,openiddict,Openiddict,如何设置表的默认方案 不幸的是,EF Core没有(据我所知)一个只接受scheme的方法,(EntityTypeBuilder.ToTable)也需要scheme旁边的表名。没有OpenIddict特定的方法来处理这个问题,但使用常规EF挂钩很容易实现。下面是一个例子: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(Db

如何设置表的默认方案


不幸的是,EF Core没有(据我所知)一个只接受scheme的方法,(
EntityTypeBuilder.ToTable
)也需要scheme旁边的表名。

没有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;
                }
            }
        }
    }
}
public类ApplicationDbContext:IdentityDbContext
{
公共应用程序DBContext(DbContextOptions选项)
:base(选项){}
模型创建时受保护的覆盖无效(ModelBuilder)
{
基于模型创建(生成器);
//自定义ASP.NET标识模型,并根据需要覆盖默认值。
//例如,可以重命名ASP.NET标识表名称等。
//在调用base.OnModelCreating(builder)后添加自定义项;
foreach(builder.Model.GetEntityTypes()中的var实体)
{
for(变量类型=实体;类型!=null;类型=类型.BaseType)
{
if(type.ClrType.Assembly==typeof(OpenIddictApplication.Assembly)
{
entity.SqlServer().Schema=“security”;
打破
}
}
}
}
}