62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MP.MONO.Data.DbModels;
|
|
|
|
namespace MP.MONO.Data
|
|
{
|
|
public class UserIdentityDbContext : IdentityDbContext
|
|
{
|
|
#region Public Constructors
|
|
|
|
public UserIdentityDbContext()
|
|
{
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options) : base(options)
|
|
{
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public DbSet<TableCount> DbSetCounts { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
string connString = DbConfig.CONNECTION_STRING;
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
var serverVersion = ServerVersion.AutoDetect(connString);
|
|
optionsBuilder.UseMySql(connString, serverVersion);
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
builder.ApplyConfiguration(new RoleConfiguration());
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |