fix(#IX8UT): PetaPoco.Mapper.Register抛异常

#Comment
comment #IX8UT

#Issue
close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IX8UT
This commit is contained in:
Argo Zhang 2019-05-30 21:56:26 +08:00
parent dabeff42bc
commit e0b4e113ec
1 changed files with 8 additions and 1 deletions

View File

@ -9,6 +9,7 @@ namespace Bootstrap.DataAccess
/// </summary>
public static class DbManager
{
private static readonly object _locker = new object();
/// <summary>
///
/// </summary>
@ -16,7 +17,13 @@ namespace Bootstrap.DataAccess
/// <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());
if (Mappers.GetMapper(typeof(Exceptions), null) == null)
{
lock (_locker)
{
if (Mappers.GetMapper(typeof(Exceptions), null) == null) Mappers.Register(typeof(Exceptions).Assembly, new BootstrapDataAccessConventionMapper());
}
}
var db = Longbow.Data.DbManager.Create(connectionName, keepAlive);
db.ExceptionThrown += (sender, args) => args.Exception.Log(new NameValueCollection() { ["LastCmd"] = db.LastCommand });
return db;