using SqlSugar;
|
using System.Configuration;
|
|
namespace TProduct.DAL
|
{
|
/// <summary>
|
/// 数据库连接辅助类
|
/// </summary>
|
public class ConnectionFactory
|
{
|
/// <summary>
|
/// 创建连接对象
|
/// </summary>
|
public static ISqlSugarClient CreateConnection<T>()
|
{
|
ISqlSugarClient conn = null;
|
var objType = typeof(T);
|
var assemblyName = objType.Assembly.ManifestModule.Name;
|
var flag = assemblyName.Replace("TProduct.Entity", "").Replace("4", "");
|
flag = flag.Replace(".dll", "");
|
ConnectionConfig connectionConfig = new ConnectionConfig()
|
{
|
DbType = SqlSugar.DbType.Sqlite,
|
ConnectionString = ConfigurationManager.ConnectionStrings["Db4" + flag].ConnectionString,
|
IsAutoCloseConnection = true,//是否自动关闭
|
};
|
conn = new SqlSugarClient(connectionConfig);
|
return conn;
|
}
|
|
}
|
}
|