45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
|
|
|
|
|
|
|
namespace MiaoYu.Repository.LiveForum.Admin
|
|
{
|
|
/// <summary>
|
|
/// 后台管理系统数据库上下文
|
|
/// </summary>
|
|
[DbContextConfig($"Repository.*.Entities.*")]
|
|
public class LiveForumAdminDbContext : DbContext, IBaseDbContext
|
|
{
|
|
/// <summary>
|
|
/// 工作单元
|
|
/// </summary>
|
|
public IUnitOfWork UnitOfWork { get; }
|
|
|
|
public LiveForumAdminDbContext(DbContextOptions<LiveForumAdminDbContext> dbContextOptions) : base(dbContextOptions)
|
|
{
|
|
UnitOfWork = new UnitOfWorkImpl<LiveForumAdminDbContext>(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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|