IdentityServer3.EntityFramework icon indicating copy to clipboard operation
IdentityServer3.EntityFramework copied to clipboard

Subclassing DbContexts and adding migrations throws

Open prochnowc opened this issue 7 years ago • 3 comments

We have a problem adding custom migrations to the DbContexts.

Because of the ConfigureChildCollections() call in the constructor of BaseDbContext we are not able to add our migrations. The overridden ConfigureChildeCollection methods retrieves EntitySets. When migrations are pending this horribly fails. To maken it even more worse: DbContext.Set<> is also virtual. It is considered bad practice to call virtual methods in constructors and in this case prevents running migrations.

prochnowc avatar Apr 03 '17 07:04 prochnowc

In that case, I'd suggest forking and doing what you need all in your own copy of the code. I don't think EF6 and its migrations were designed for library developers.

brockallen avatar Apr 03 '17 13:04 brockallen

Your statement about migrations in libraries is totally valid. Thats why we created our own migrations for DbContexts from IdentityServer3.EntityFramework in our application. The problem is that the design of the IDSRV DbContexts is broken. Migrator instantiates the DbContext to build the model. And because you fetch EntitySets in the ctor this breaks. If you dont want to fix this, maybe you will accept PRs for this issue?

prochnowc avatar Apr 03 '17 16:04 prochnowc

Sure, as long as it's not a major breaking change. If it needs to be, then we'll push it to 3.0 release

brockallen avatar Apr 03 '17 17:04 brockallen