FieldWorkClient/Provider/SqlSugarConfig.cs

41 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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");
}
}
}