diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs index 5eff3195c9..89d69f3d24 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs @@ -65,7 +65,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.GrantType }); + b.HasKey(x => new {x.ClientId, x.GrantType}); b.Property(x => x.GrantType).HasMaxLength(ClientGrantTypeConsts.GrantTypeMaxLength).IsRequired(); }); @@ -76,15 +76,16 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.RedirectUri }); + b.HasKey(x => new {x.ClientId, x.RedirectUri}); - if (IsMySql(builder, options)) + if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql)) { b.Property(x => x.RedirectUri).HasMaxLength(300).IsRequired(); } else { - b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLength).IsRequired(); + b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLength) + .IsRequired(); } }); @@ -94,15 +95,16 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.PostLogoutRedirectUri }); + b.HasKey(x => new {x.ClientId, x.PostLogoutRedirectUri}); - if (IsMySql(builder, options)) + if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql)) { b.Property(x => x.PostLogoutRedirectUri).HasMaxLength(300).IsRequired(); } else { - b.Property(x => x.PostLogoutRedirectUri).HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLength).IsRequired(); + b.Property(x => x.PostLogoutRedirectUri) + .HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLength).IsRequired(); } }); @@ -112,7 +114,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.Scope }); + b.HasKey(x => new {x.ClientId, x.Scope}); b.Property(x => x.Scope).HasMaxLength(ClientScopeConsts.ScopeMaxLength).IsRequired(); }); @@ -123,11 +125,11 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.Type, x.Value }); + b.HasKey(x => new {x.ClientId, x.Type, x.Value}); b.Property(x => x.Type).HasMaxLength(SecretConsts.TypeMaxLength).IsRequired(); - if (IsMySql(builder, options)) + if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { b.Property(x => x.Value).HasMaxLength(300).IsRequired(); } @@ -145,7 +147,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.Type, x.Value }); + b.HasKey(x => new {x.ClientId, x.Type, x.Value}); b.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired(); @@ -157,7 +159,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.Provider }); + b.HasKey(x => new {x.ClientId, x.Provider}); b.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired(); }); @@ -168,7 +170,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.Origin }); + b.HasKey(x => new {x.ClientId, x.Origin}); b.Property(x => x.Origin).HasMaxLength(ClientCorsOriginConsts.OriginMaxLength).IsRequired(); }); @@ -179,7 +181,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ClientId, x.Key }); + b.HasKey(x => new {x.ClientId, x.Key}); b.Property(x => x.Key).HasMaxLength(ClientPropertyConsts.KeyMaxLength).IsRequired(); b.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired(); @@ -197,7 +199,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.Property(x => x.ClientId).HasMaxLength(PersistedGrantConsts.ClientIdMaxLength).IsRequired(); b.Property(x => x.CreationTime).IsRequired(); - if (IsMySql(builder, options)) + if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql)) { b.Property(x => x.Data).HasMaxLength(10000).IsRequired(); } @@ -208,7 +210,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.HasKey(x => x.Key); //TODO: What about Id!!! - b.HasIndex(x => new { x.SubjectId, x.ClientId, x.Type }); + b.HasIndex(x => new {x.SubjectId, x.ClientId, x.Type}); b.HasIndex(x => x.Expiration); }); @@ -234,7 +236,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.IdentityResourceId, x.Type }); + b.HasKey(x => new {x.IdentityResourceId, x.Type}); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); }); @@ -263,12 +265,12 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ApiResourceId, x.Type, x.Value }); + b.HasKey(x => new {x.ApiResourceId, x.Type, x.Value}); b.Property(x => x.Type).HasMaxLength(SecretConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Description).HasMaxLength(SecretConsts.DescriptionMaxLength); - if (IsMySql(builder, options)) + if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { b.Property(x => x.Value).HasMaxLength(300).IsRequired(); } @@ -284,7 +286,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ApiResourceId, x.Type }); + b.HasKey(x => new {x.ApiResourceId, x.Type}); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); }); @@ -295,13 +297,13 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ApiResourceId, x.Name }); + b.HasKey(x => new {x.ApiResourceId, x.Name}); b.Property(x => x.Name).HasMaxLength(ApiScopeConsts.NameMaxLength).IsRequired(); b.Property(x => x.DisplayName).HasMaxLength(ApiScopeConsts.DisplayNameMaxLength); b.Property(x => x.Description).HasMaxLength(ApiScopeConsts.DescriptionMaxLength); - b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => new { x.ApiResourceId, x.Name }).IsRequired(); + b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => new {x.ApiResourceId, x.Name}).IsRequired(); }); builder.Entity(b => @@ -310,7 +312,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new { x.ApiResourceId, x.Name, x.Type }); + b.HasKey(x => new {x.ApiResourceId, x.Name, x.Type}); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Name).HasMaxLength(ApiScopeConsts.NameMaxLength).IsRequired(); @@ -329,18 +331,27 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.Property(x => x.Expiration).IsRequired(); b.Property(x => x.Data).HasMaxLength(50000).IsRequired(); - b.HasIndex(x => new { x.UserCode }).IsUnique(); + b.HasIndex(x => new {x.UserCode}).IsUnique(); b.HasIndex(x => x.DeviceCode).IsUnique(); b.HasIndex(x => x.Expiration); }); } - private static bool IsMySql( + private static bool IsDatabaseProvider( ModelBuilder modelBuilder, - IdentityServerModelBuilderConfigurationOptions options) + IdentityServerModelBuilderConfigurationOptions options, + params EfCoreDatabaseProvider[] providers) { - return options.DatabaseProvider == EfCoreDatabaseProvider.MySql || - modelBuilder.IsUsingMySQL(); + foreach (var provider in providers) + { + if (options.DatabaseProvider == EfCoreDatabaseProvider.MySql || + modelBuilder.GetDatabaseProvider() == provider) + { + return true; + } + } + + return false; } } -} +} \ No newline at end of file