2024-11-13 18:18:28 +08:00

47 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
public class g
{
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() =>
{
string dataSubDirectory = Path.Combine(AppContext.BaseDirectory);
if (!Directory.Exists(dataSubDirectory))
Directory.CreateDirectory(dataSubDirectory);
AppDomain.CurrentDomain.SetData("DataDirectory", dataSubDirectory);
var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|local.db")
//.UseConnectionFactory(FreeSql.DataType.Sqlite, () =>
//{
// var conn = new System.Data.SQLite.SQLiteConnection(@"Data Source=|DataDirectory|\document.db;Pooling=true;");
// //conn.Open();
// //var cmd = conn.CreateCommand();
// //cmd.CommandText = $"attach database [xxxtb.db] as [xxxtb];\r\n";
// //cmd.ExecuteNonQuery();
// //cmd.Dispose();
// return conn;
//})
.UseAutoSyncStructure(true)
//.UseGenerateCommandParameterWithLambda(true)
.UseLazyLoading(true)
.UseMonitorCommand(
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象在执行前
//, (cmd, traceLog) => Console.WriteLine(traceLog)
)
.Build();
return fsql;
}
);
public static IFreeSql sqlite => sqliteLazy.Value;
}