using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; using CellularManagement.Domain.Entities; using CellularManagement.Domain.Entities.Logging; using CellularManagement.Domain.Entities.Device; namespace CellularManagement.Infrastructure.Context; /// /// 应用程序数据库上下文 /// 继承自 IdentityDbContext 以支持身份认证 /// public class AppDbContext : IdentityDbContext { private readonly ILogger _logger; /// /// 用户角色关系 /// public new DbSet UserRoles { get; set; } = null!; /// /// 权限集合 /// public DbSet Permissions { get; set; } = null!; /// /// 角色权限关联集合 /// public DbSet RolePermissions { get; set; } = null!; /// /// 用户登录日志 /// public DbSet LoginLogs { get; set; } = null!; /// /// 蜂窝设备集合 /// public DbSet CellularDevices { get; set; } = null!; /// /// 协议版本集合 /// public DbSet ProtocolVersions { get; set; } = null!; /// /// 网络配置集合 /// public DbSet NetworkConfigs { get; set; } = null!; /// /// 场景集合 /// public DbSet Scenarios { get; set; } = null!; /// /// 初始化数据库上下文 /// /// 数据库上下文选项 /// 日志记录器 public AppDbContext(DbContextOptions options, ILogger logger) : base(options) { _logger = logger; } /// /// 配置实体模型 /// /// 模型构建器 protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // 应用所有的实体配置 modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly); // 忽略其他 Identity 相关的实体 modelBuilder.Ignore>(); modelBuilder.Ignore>(); modelBuilder.Ignore>(); modelBuilder.Ignore>(); modelBuilder.Ignore>(); } }