From e96192bdedee3196cc1fda73f58774d89b3a8605 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 11 May 2019 12:12:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor(project):=20=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=BB=84=E4=BB=B6=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Longbow.Dat 2.3.0 Bootstrap.Security.DataAccess 2.2.0 PetaPoco.Compiled 6.0.403 PetaPoco.Extensions 1.0.4 增加BootstrapDataAccessConventionMapper适应BA数据库对应关系 --- .../Bootstrap.Client.DataAccess.csproj | 4 +- Bootstrap.DataAccess/App.cs | 2 +- .../Bootstrap.DataAccess.csproj | 5 +- .../BootstrapDataAccessConventionMapper.cs | 50 +++++++++++++++++++ Bootstrap.DataAccess/DbManager.cs | 1 + Bootstrap.DataAccess/Menu.cs | 2 +- 6 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 Bootstrap.DataAccess/BootstrapDataAccessConventionMapper.cs diff --git a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index 1639516c..a275705a 100644 --- a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -11,9 +11,9 @@ - + - + diff --git a/Bootstrap.DataAccess/App.cs b/Bootstrap.DataAccess/App.cs index 35b0c10b..9dd4f90b 100644 --- a/Bootstrap.DataAccess/App.cs +++ b/Bootstrap.DataAccess/App.cs @@ -1,5 +1,5 @@ using Bootstrap.Security.DataAccess; -using Longbow.Data; +using PetaPoco; using System; using System.Collections.Generic; using System.Linq; diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 11b9015b..ace11d46 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -11,14 +11,15 @@ - - + + + diff --git a/Bootstrap.DataAccess/BootstrapDataAccessConventionMapper.cs b/Bootstrap.DataAccess/BootstrapDataAccessConventionMapper.cs new file mode 100644 index 00000000..6ffec01a --- /dev/null +++ b/Bootstrap.DataAccess/BootstrapDataAccessConventionMapper.cs @@ -0,0 +1,50 @@ +using PetaPoco; +using System; +using System.Reflection; + +namespace Bootstrap.DataAccess +{ + internal class BootstrapDataAccessConventionMapper : IMapper + { + private readonly IMapper _mapper; + + public BootstrapDataAccessConventionMapper() + { + _mapper = new ConventionMapper(); + } + + /// + /// + /// + /// + /// + public ColumnInfo GetColumnInfo(PropertyInfo pocoProperty) => _mapper.GetColumnInfo(pocoProperty); + + /// + /// + /// + /// + /// + /// + public Func GetFromDbConverter(PropertyInfo targetProperty, Type sourceType) => _mapper.GetFromDbConverter(targetProperty, sourceType); + + /// + /// + /// + /// + /// + public TableInfo GetTableInfo(Type pocoType) + { + var ti = _mapper.GetTableInfo(pocoType); + ti.AutoIncrement = true; + return ti; + } + + /// + /// + /// + /// + /// + public Func GetToDbConverter(PropertyInfo sourceProperty) => _mapper.GetToDbConverter(sourceProperty); + } +} diff --git a/Bootstrap.DataAccess/DbManager.cs b/Bootstrap.DataAccess/DbManager.cs index 9a3ed949..0ea0ef27 100644 --- a/Bootstrap.DataAccess/DbManager.cs +++ b/Bootstrap.DataAccess/DbManager.cs @@ -16,6 +16,7 @@ namespace Bootstrap.DataAccess /// public static IDatabase Create(string connectionName = null, bool keepAlive = false) { + 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; diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 1a7a7a1a..b5aeb329 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -1,6 +1,6 @@ using Bootstrap.Security; using Bootstrap.Security.DataAccess; -using Longbow.Data; +using PetaPoco; using System; using System.Collections.Generic; using System.Linq;