251029
This commit is contained in:
33
FATrace.App/FSqlContext.cs
Normal file
33
FATrace.App/FSqlContext.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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(true)
|
||||
.Build();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("初始化数据库连接失败,请检查连接字符串与数据库网络连通性。", ex);
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// 获取单例数据库实例。
|
||||
/// </summary>
|
||||
public static IFreeSql FDb => LazyFreeSql.Value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user