BootstrapAdmin/Bootstrap.DataAccess/DbManager.cs

27 lines
943 B
C#
Raw Normal View History

2019-05-01 16:46:24 +08:00
using PetaPoco;
using System;
using System.Collections.Specialized;
namespace Bootstrap.DataAccess
{
/// <summary>
2019-08-29 18:11:24 +08:00
/// 数据库对象管理类
2019-05-01 16:46:24 +08:00
/// </summary>
public static class DbManager
{
/// <summary>
2019-08-29 18:11:24 +08:00
/// 创建 IDatabase 实例方法
2019-05-01 16:46:24 +08:00
/// </summary>
/// <param name="connectionName"></param>
2019-06-24 10:42:59 +08:00
/// <param name="keepAlive"></param>
2019-05-01 16:46:24 +08:00
/// <returns></returns>
public static IDatabase Create(string connectionName = null, bool keepAlive = false)
{
if (Mappers.GetMapper(typeof(Exceptions), null) == null) Mappers.Register(typeof(Exceptions).Assembly, new BootstrapDataAccessConventionMapper());
2019-05-01 16:46:24 +08:00
var db = Longbow.Data.DbManager.Create(connectionName, keepAlive);
db.ExceptionThrown += (sender, args) => args.Exception.Log(new NameValueCollection() { ["LastCmd"] = db.LastCommand });
2019-05-10 19:46:36 +08:00
return db;
2019-05-01 16:46:24 +08:00
}
}
}