44 lines
1.8 KiB
C#
44 lines
1.8 KiB
C#
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
|
|
namespace Netina.Repository.Models;
|
|
|
|
|
|
public class ApplicationContext(DbContextOptions<ApplicationContext> options, ILogger<ApplicationContext> logger)
|
|
: IdentityDbContext<ApplicationUser, ApplicationRole, Guid>(options)
|
|
{
|
|
private readonly Assembly _projectAssembly = options.GetExtension<DbContextOptionCustomExtensions>().ProjectAssembly;
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
var stopwatch = new Stopwatch();
|
|
stopwatch.Start();
|
|
base.OnModelCreating(builder);
|
|
var entitiesAssembly = _projectAssembly;
|
|
builder.RegisterAllEntities<ApiEntity>(logger, entitiesAssembly);
|
|
stopwatch.Stop();
|
|
logger.LogInformation($"!!!!!!! RegisterAllEntities : {stopwatch.ElapsedMilliseconds}ms !!!!!!!");
|
|
|
|
|
|
builder.HasPostgresExtension("pg_trgm");
|
|
builder.HasPostgresExtension("fuzzystrmatch");
|
|
|
|
RenameIdentityTables(builder);
|
|
builder.RegisterEntityTypeConfiguration(entitiesAssembly);
|
|
builder.AddPluralizingTableNameConvention();
|
|
builder.AddRestrictDeleteBehaviorConvention();
|
|
|
|
//builder.AddSequentialGuidForIdConvention();
|
|
}
|
|
protected void RenameIdentityTables(ModelBuilder builder)
|
|
{
|
|
builder.HasDefaultSchema("public");
|
|
builder.Entity<ApplicationUser>().ToTable("Users");
|
|
builder.Entity<ApplicationRole>().ToTable("Roles");
|
|
|
|
builder.Entity<IdentityRoleClaim<Guid>>().ToTable("RoleClaims");
|
|
builder.Entity<IdentityUserRole<Guid>>().ToTable("UserRoles");
|
|
builder.Entity<IdentityUserClaim<Guid>>().ToTable("Claims");
|
|
builder.Entity<IdentityUserLogin<Guid>>().ToTable("Logins");
|
|
builder.Entity<IdentityUserToken<Guid>>().ToTable("Tokens");
|
|
|
|
}
|
|
} |