61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using MagMan.Data.Admin.DbModels;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MagMan.Data.Admin
|
|
{
|
|
public class IdentityContext : IdentityDbContext
|
|
{
|
|
#region Public Constructors
|
|
|
|
public IdentityContext()
|
|
{
|
|
}
|
|
|
|
public IdentityContext(DbContextOptions<IdentityContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public virtual 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 = DbConfig.MysqlServerVersion(connString);
|
|
optionsBuilder.UseMySql(connString, serverVersion);
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
// Gestione in blocco user/permessi di base (salvata con migrazione AddUserAndRoles) come in GWMS + https://stackoverflow.com/questions/34343599/how-to-seed-users-and-roles-with-code-first-migration-using-identity-asp-net-cor
|
|
|
|
// disattivo riferimento view x avere oggetto davvero fittizio
|
|
builder.Entity<TableCount>().ToView(null);
|
|
|
|
builder.Seed();
|
|
base.OnModelCreating(builder);
|
|
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
}
|