FieldWorkClient/Provider/SqlSugarConfig.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2025-04-02 09:30:13 +08:00
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hopetry.Provider
{
public class SqlSugarConfig
{
public static SqlSugarScope GetSqlSugarScope()
{
return new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = $"Data Source={GetDbPath()};Version=3;", // 数据库路径
DbType = DbType.Sqlite, // 数据库类型
IsAutoCloseConnection = true, // 自动释放
InitKeyType = InitKeyType.Attribute // 从实体特性中读取主键信息
},
db =>
{
// 配置AOP
db.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine(sql); // 输出SQL
};
});
}
private static string GetDbPath()
{
// 这里假设数据库放在应用程序根目录下
// 对于WPF项目可以使用AppDomain.CurrentDomain.BaseDirectory获取基目录
var basePath = AppDomain.CurrentDomain.BaseDirectory;
return Path.Combine(basePath, "minio.db");
}
}
}