I have the following code in my DbContext
protected override void OnModelCreating(ModelBuilder builder)
{
// ...
// Shorten key length for Identity
builder.Entity<ApplicationUser>(entity => entity.Property(m => m.Id).HasMaxLength(127));
builder.Entity<IdentityRole>(entity => entity.Property(m => m.Id).HasMaxLength(127));
builder.Entity<IdentityUserLogin<string>>(entity =>
{
entity.Property(m => m.LoginProvider).HasMaxLength(127);
entity.Property(m => m.ProviderKey).HasMaxLength(127);
});
builder.Entity<IdentityUserRole<string>>(entity =>
{
entity.Property(m => m.UserId).HasMaxLength(127);
entity.Property(m => m.RoleId).HasMaxLength(127);
});
builder.Entity<IdentityUserToken<string>>(entity =>
{
entity.Property(m => m.UserId).HasMaxLength(127);
entity.Property(m => m.LoginProvider).HasMaxLength(127);
entity.Property(m => m.Name).HasMaxLength(127);
});
I only want to apply these changes to the models if the server/provider being used is MySQL. What is the best way to do that?
This answer suggests the following which feels hacky
DbContext.Database.Connection.GetType().Name
This answer suggests using checks such as Database.IsSqlServer()
which is fine but I cannot find a Database.IsMySqlServer()
method anywhere
Please help. Thanks.