54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
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) ;
|
|
}
|
|
}
|
|
}
|