初始化
This commit is contained in:
53
COMMON/XC_Data.cs
Normal file
53
COMMON/XC_Data.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models;
|
||||
using Models.Models.LOGDB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace COMMON
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取ef
|
||||
/// </summary>
|
||||
public class XC_Data
|
||||
{
|
||||
private static object locks = new object();
|
||||
/// <summary>
|
||||
/// 获取主要数据库 每次都会创建一个实例 不建议使用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static HotelServiceContext GetMinDataBase()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<HotelServiceContext>();
|
||||
if(ConfigEntity.Instance.DBTYPE == 1)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(ConfigEntity.Instance.Connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseMySQL(ConfigEntity.Instance.Connection);
|
||||
}
|
||||
return new HotelServiceContext(optionsBuilder.Options);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取日志数据库 每次都会创建一个实例 不建议使用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static LOG_DBContext GetLogDataBase()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<LOG_DBContext>();
|
||||
if (ConfigEntity.Instance.DBTYPE == 1)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(ConfigEntity.Instance.Connection_log);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseMySQL(ConfigEntity.Instance.Connection_log);
|
||||
}
|
||||
return new LOG_DBContext(optionsBuilder.Options) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user