using Microsoft.EntityFrameworkCore;
using Tiobon.Core.Common.DB;

namespace Tiobon.Core.DataAccess;

/// <summary>
/// 直接创建 Context
/// </summary>
public class ContextFactory
{
    /// <summary>
    /// 创建DbContext
    /// </summary>
    /// <returns></returns>
    public static DataContext CreateContext()
    {
        var builder = new DbContextOptionsBuilder<DataContext>();

        var mainConnetctDb = BaseDBConfig.MutiConnectionString.allDbs.Find(x => x.ConnId == MainDb.CurrentDbConnId);
        builder.UseSqlServer(mainConnetctDb.Connection);
        return new DataContext(builder.Options);
    }
}
