34 lines
1022 B
C#
34 lines
1022 B
C#
using FATrace.Com;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FATrace.App
|
|
{
|
|
public class FSqlContext
|
|
{
|
|
private static readonly Lazy<IFreeSql> LazyFreeSql = new Lazy<IFreeSql>(() =>
|
|
{
|
|
var connectionString = ConfigHelper.GetRequiredConnectionString("connecting");
|
|
try
|
|
{
|
|
return new FreeSql.FreeSqlBuilder()
|
|
.UseConnectionString(FreeSql.DataType.SqlServer, connectionString)
|
|
.UseAutoSyncStructure(false)
|
|
.Build();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new InvalidOperationException("初始化数据库连接失败,请检查连接字符串与数据库网络连通性。", ex);
|
|
}
|
|
});
|
|
|
|
/// <summary>
|
|
/// 获取单例数据库实例。
|
|
/// </summary>
|
|
public static IFreeSql FDb => LazyFreeSql.Value;
|
|
}
|
|
}
|