using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; using X1.Domain.Entities; using X1.Domain.Entities.Logging; using X1.Domain.Entities.Device; using X1.Domain.Entities.NetworkProfile; using X1.Domain.Entities.Terminal; using X1.Domain.Entities.TestCase; namespace X1.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 ProtocolLogs { get; set; } = null!; /// /// 蜂窝设备集合 /// public DbSet CellularDevices { get; set; } = null!; /// /// 协议版本集合 /// public DbSet ProtocolVersions { get; set; } = null!; /// /// 蜂窝设备运行时状态集合 /// public DbSet CellularDeviceRuntimes { get; set; } = null!; /// /// RAN配置集合 /// public DbSet RAN_Configurations { get; set; } = null!; /// /// 核心网配置集合 /// public DbSet CoreNetworkConfigs { get; set; } = null!; /// /// IMS配置集合 /// public DbSet IMS_Configurations { get; set; } = null!; /// /// 网络栈配置集合 /// public DbSet NetworkStackConfigs { get; set; } = null!; /// /// 栈与核心网/IMS绑定关系集合 /// public DbSet Stack_CoreIMS_Bindings { get; set; } = null!; /// /// 终端服务集合 /// public DbSet TerminalServices { get; set; } = null!; /// /// 终端设备集合 /// public DbSet TerminalDevices { get; set; } = null!; /// /// ADB操作集合 /// public DbSet AdbOperations { get; set; } = null!; /// /// AT操作集合 /// public DbSet AtOperations { get; set; } = null!; /// /// 用例步骤配置集合 /// public DbSet CaseStepConfigs { get; set; } = null!; /// /// 测试用例流程集合 /// public DbSet TestCaseFlows { get; set; } = null!; /// /// 测试用例节点集合 /// public DbSet TestCaseNodes { get; set; } = null!; /// /// 测试用例连线集合 /// public DbSet TestCaseEdges { get; set; } = null!; /// /// IMSI注册记录集合 /// public DbSet ImsiRegistrationRecords { get; set; } = null!; /// /// 测试场景集合 /// public DbSet TestScenarios { get; set; } = null!; /// /// 场景测试用例集合 /// public DbSet ScenarioTestCases { 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>(); // 使用自定义的 UserRole 实体 } }