/// <summary> /// 创建上下文数据模型时,对各个实体类的数据库映射细节进行配置 /// </summary> /// <param name="modelBuilder">上下文数据模型构建器</param> protected override void OnModelCreating(ModelBuilder modelBuilder) { //通过实体配置信息将实体注册到当前上下文 IEntityRegister[] registers = _typeFinder.GetEntityRegisters(typeof(TDbContext)); foreach (IEntityRegister register in registers) { register.RegistTo(modelBuilder); } }
/// <summary> /// 创建上下文数据模型时,对各个实体类的数据库映射细节进行配置 /// </summary> /// <param name="modelBuilder">上下文数据模型构建器</param> protected override void OnModelCreating(ModelBuilder modelBuilder) { //通过实体配置信息将实体注册到当前上下文 Type contextType = GetType(); IEntityRegister[] registers = _typeFinder.GetEntityRegisters(contextType); foreach (IEntityRegister register in registers) { register.RegistTo(modelBuilder); _logger?.LogDebug($"将实体类“{register.EntityType}”注册到上下文“{contextType}”中"); } _logger?.LogInformation($"上下文“{contextType}”注册了{registers.Length}个实体类"); }