45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
|
|
|
using MiaoYu.Repository.ChatAI.Admin.Entities.Apps;
|
|
|
|
namespace MiaoYu.Repository.ChatAI.Admin
|
|
{
|
|
/// <summary>
|
|
/// 后台管理系统数据库上下文
|
|
/// </summary>
|
|
[DbContextConfig($"Repository.*.Entities.*")]
|
|
public class ChatAdminDbContext : DbContext, IBaseDbContext
|
|
{
|
|
/// <summary>
|
|
/// 工作单元
|
|
/// </summary>
|
|
public IUnitOfWork UnitOfWork { get; }
|
|
|
|
public ChatAdminDbContext(DbContextOptions<ChatAdminDbContext> dbContextOptions) : base(dbContextOptions)
|
|
{
|
|
UnitOfWork = new UnitOfWorkImpl<ChatAdminDbContext>(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 模型创建
|
|
/// </summary>
|
|
/// <param name="modelBuilder"></param>
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
#region 自动迁移种子数据
|
|
|
|
//OnModelCreatingPartial(modelBuilder);
|
|
//ModelBuilderExtensions.Seed(modelBuilder);
|
|
|
|
#endregion
|
|
var dbContextConfigAttribute = GetType().GetCustomAttribute<DbContextConfigAttribute>()!;
|
|
var t = dbContextConfigAttribute.GetModelTypes(GetType());
|
|
dbContextConfigAttribute!.OnModelCreating(modelBuilder, t);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|