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;