【问题标题】:How to set default scheme for Openiddict-core tables in EF Core如何在 EF Core 中为 Openiddict-core 表设置默认方案
【发布时间】:2019-07-02 13:07:32
【问题描述】:

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

不幸的是,EF Core 没有(我不知道)只接受方案的方法,并且 (EntityTypeBuilder.ToTable) 除了方案之外还需要表名。

【问题讨论】:

    标签: openiddict


    【解决方案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;
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-04
      • 2020-05-04
      • 2020-06-14
      • 2018-06-25
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 2019-06-15
      相关资源
      最近更新 更多