Identityserver4: How to change "MaxIdentifierLength" for PersistedGrantDbContext migration?

Created on 15 Apr 2019  路  10Comments  路  Source: IdentityServer/IdentityServer4

We do not access PersistedGrantDbContext to change, override or configure. I have restricted time to create my PersistedGrant store on Oracle database. I need to change MaxIdentifierLength property for Oracle migration compatibility. What is your recommendation? Thanks a lot.

Most helpful comment

It would be the constructor causing that issue. Try updating your dbcontext to look like the following:

public class ApplicationConfigurationDbContext : ConfigurationDbContext<ApplicationConfigurationDbContext>
{
    public ApplicationConfigurationDbContext(DbContextOptions<ApplicationConfigurationDbContext> options, ConfigurationStoreOptions storeOptions)
        : base(options, storeOptions)
    {
    }

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

        builder.Model.Relational().MaxIdentifierLength = 30;
    }
}

All 10 comments

What MaxIdentifierLength are you referring to?

We can use MaxIdentifierLength property like:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Model.Relational().MaxIdentifierLength = 30; //instead of 128
}
for building Oracle migration, because Oracle can not accept object identifiers or names greater than 30 characters. Actually I want to know how can I access OnModelCreating method for PersistedGrantDbContext. Thanks.

I'd suggest wiring up the DbContext classes yourself in DI and doing the config yourself. You can use our DbContext classes, but you don't have to use our config and DI APIs.

Do you mean I can inherit from PersistedGrantDbContext or ConfigurationDbContext classes and do the configuration in overridden methods? Then using the following method for registering in DI:
.AddConfigurationStore<InheritedConfigurationDbContext>(...)
Am I right?

An other problem in migrating to Oracle, is Identity Column. For example, the Oracle migration produce this line for "ApiResources" entity:
Id = table.Column<int>(nullable: false) .Annotation("Oracle:ValueGenerationStrategy", OracleValueGenerationStrategy.IdentityColumn),
unfortunately this is not supported in Oracle 11g. Should or can I change the primary key data types from identity int to Guid?

I have created my own ConfigurationDbContext like this:

public class ApplicationConfigurationDbContext : ConfigurationDbContext
{
    public ApplicationConfigurationDbContext(DbContextOptions<ConfigurationDbContext> options, ConfigurationStoreOptions storeOptions)
        : base(options, storeOptions)
    {
    }

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

        builder.Model.Relational().MaxIdentifierLength = 30;
    }

}

and register for identityserver with:
.AddConfigurationStore<ApplicationConfigurationDbContext>(options => ...

migration process thrown the Autofac exception:

Cannot resolve parameter 'Microsoft.EntityFrameworkCore.DbContextOptions1[IdentityServer4.EntityFramework.DbContexts.ConfigurationDbContext] options' of constructor 'Void .ctor(Microsoft.EntityFrameworkCore.DbContextOptions1[IdentityServer4.EntityFramework.DbContexts.ConfigurationDbContext], IdentityServer4.EntityFramework.Options.ConfigurationStoreOptions)'. (See inner exception for details.)

Should I register any thing else like DbContextOptions in DI?

It would be the constructor causing that issue. Try updating your dbcontext to look like the following:

public class ApplicationConfigurationDbContext : ConfigurationDbContext<ApplicationConfigurationDbContext>
{
    public ApplicationConfigurationDbContext(DbContextOptions<ApplicationConfigurationDbContext> options, ConfigurationStoreOptions storeOptions)
        : base(options, storeOptions)
    {
    }

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

        builder.Model.Relational().MaxIdentifierLength = 30;
    }
}

@scottbrady91 your comment solved my problem. Thank you very much.

An other problem in migrating to Oracle, is Identity Column. For example, the Oracle migration produce this line for "ApiResources" entity:
Id = table.Column<int>(nullable: false) .Annotation("Oracle:ValueGenerationStrategy", OracleValueGenerationStrategy.IdentityColumn),
unfortunately this is not supported in Oracle 11g. Should or can I change the primary key data types from identity int to Guid?

Do you handle with this somehow? :)

@squizee:
yes, we moved to Oracle 12c!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings