Following on from last weeks tangle
on key lengths, I need some advice on coercion operators between types using MySql.
Part of last week's trouble was that I failed to adequately explain what I needed so hopefully I will not fall into that trap this time.
To recap, I am attempting to use the combined example from the Identity Server site but targetting MySql rather than SqlServer (Where I note a fine new article from HHerzl).
Due to how MySql holds Booleans in Integer fields when the EF hits a boolean I get: "No coercion operator is defined between types 'System.Int16' and 'System.Boolean'."
The example comes with three contexts, but only one of them, ApplicationDbContext, is referenced in the source code. For that one, I can resolve the issue in OnModelCreating using:
.Property(u => u.EmailConfirmed).HasConversion<Int16>()
The trouble is the other two contexts, e.g. ConfigurationDbContext, are part of IdentityServer4.EntityFramework.DbContexts so the source is not part of the example. I have a number of choices and I need some advice on what direction I should take. I see these as my options:
Replace MySql with SqlServer
Probably the easiest thing to do, and despite my code having components that go back more than 10 years, the effort would not be huge because the database dependent calls were kept seperate from day 1 for this eventuality. But I like MySql.
Extend ConfigurationDbContext via a partial class
This would allow me to add an OnModelCreating method via the partial. But I'm not sure that this is techincally possible since the original definition is not a partial.
Create a new context that inherits from ConfigurationDbContext
This is looking increasingly like the solution of choice although it is a little more effort than either of the previous two.
Pull down a copy of the IdentityServer4 code itself and modify ConfigurationDbContext class
This would give me considerable power to overcome the MySql roadblocks but at the expense of comming off the 'upgrade path' of the Identity Server nuget packages. I would be reluctant to go down that road.
Something else not listed here
So in summary I need advice on how I might add an OnModelCreating method to the IdentitySever ConfigurationDbContext class.
What I have tried:
I have resolved the issue in one of the three places it occurs, then researched and listed possibilities for resolving it in the other two. Now I need advice on the direction to take.