You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.5 KiB

8 months ago
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;
using CellularManagement.Domain.Entities.NetworkProfile;
8 months ago
namespace CellularManagement.Infrastructure.Context;
/// <summary>
/// 应用程序数据库上下文
/// 继承自 IdentityDbContext 以支持身份认证
/// </summary>
public class AppDbContext : IdentityDbContext<AppUser, AppRole, string>
{
private readonly ILogger<AppDbContext> _logger;
/// <summary>
/// 用户角色关系
/// </summary>
public new DbSet<UserRole> UserRoles { get; set; } = null!;
/// <summary>
/// 权限集合
/// </summary>
public DbSet<Permission> Permissions { get; set; } = null!;
/// <summary>
/// 角色权限关联集合
/// </summary>
public DbSet<RolePermission> RolePermissions { get; set; } = null!;
/// <summary>
/// 用户登录日志
/// </summary>
public DbSet<LoginLog> LoginLogs { get; set; } = null!;
/// <summary>
/// 协议日志集合
/// </summary>
public DbSet<ProtocolLog> ProtocolLogs { get; set; } = null!;
7 months ago
/// <summary>
/// 蜂窝设备集合
7 months ago
/// </summary>
public DbSet<CellularDevice> CellularDevices { get; set; } = null!;
/// <summary>
/// 协议版本集合
/// </summary>
public DbSet<ProtocolVersion> ProtocolVersions { get; set; } = null!;
7 months ago
/// <summary>
/// 蜂窝设备运行时状态集合
/// </summary>
public DbSet<CellularDeviceRuntime> CellularDeviceRuntimes { get; set; } = null!;
/// <summary>
/// RAN配置集合
/// </summary>
public DbSet<RAN_Configuration> RAN_Configurations { get; set; } = null!;
/// <summary>
/// 核心网配置集合
/// </summary>
public DbSet<CoreNetworkConfig> CoreNetworkConfigs { get; set; } = null!;
/// <summary>
/// IMS配置集合
/// </summary>
public DbSet<IMS_Configuration> IMS_Configurations { get; set; } = null!;
/// <summary>
/// 网络栈配置集合
/// </summary>
public DbSet<NetworkStackConfig> NetworkStackConfigs { get; set; } = null!;
/// <summary>
/// 栈与核心网/IMS绑定关系集合
/// </summary>
public DbSet<Stack_CoreIMS_Binding> Stack_CoreIMS_Bindings { get; set; } = null!;
8 months ago
/// <summary>
/// 初始化数据库上下文
/// </summary>
/// <param name="options">数据库上下文选项</param>
/// <param name="logger">日志记录器</param>
public AppDbContext(DbContextOptions<AppDbContext> options, ILogger<AppDbContext> logger)
: base(options)
{
_logger = logger;
}
/// <summary>
/// 配置实体模型
/// </summary>
/// <param name="modelBuilder">模型构建器</param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// 应用所有的实体配置
modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
// 忽略其他 Identity 相关的实体
8 months ago
modelBuilder.Ignore<IdentityUserLogin<string>>();
modelBuilder.Ignore<IdentityRoleClaim<string>>();
modelBuilder.Ignore<IdentityUserClaim<string>>();
modelBuilder.Ignore<IdentityUserToken<string>>();
modelBuilder.Ignore<IdentityUserRole<string>>();
}
}