From d1dbad8e8bb24b2d6b42cd11e535fd38efce17d0 Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Tue, 5 May 2020 19:59:19 +0200 Subject: [PATCH] Add conventions to the Dommel column name resolver #112 --- .../Dapper.FluentMap.Dommel.csproj | 2 +- .../Resolvers/DommelColumnNameResolver.cs | 21 ++++++++++++++++--- .../Conventions/Convention.cs | 10 +++++++-- src/Dapper.FluentMap/Dapper.FluentMap.csproj | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Dapper.FluentMap.Dommel/Dapper.FluentMap.Dommel.csproj b/src/Dapper.FluentMap.Dommel/Dapper.FluentMap.Dommel.csproj index 115bd6b..1bd9115 100644 --- a/src/Dapper.FluentMap.Dommel/Dapper.FluentMap.Dommel.csproj +++ b/src/Dapper.FluentMap.Dommel/Dapper.FluentMap.Dommel.csproj @@ -2,7 +2,7 @@ Dapper.FluentMap extension for Dommel support. Copyright © Henk Mollema 2017 - 1.7.0 + 1.7.1 Henk Mollema net451;netstandard1.3;netstandard2.0 true diff --git a/src/Dapper.FluentMap.Dommel/Resolvers/DommelColumnNameResolver.cs b/src/Dapper.FluentMap.Dommel/Resolvers/DommelColumnNameResolver.cs index 68d053c..6e3a71a 100644 --- a/src/Dapper.FluentMap.Dommel/Resolvers/DommelColumnNameResolver.cs +++ b/src/Dapper.FluentMap.Dommel/Resolvers/DommelColumnNameResolver.cs @@ -16,12 +16,11 @@ public string ResolveColumnName(PropertyInfo propertyInfo) { if (propertyInfo.DeclaringType != null) { - IEntityMap entityMap; #if NETSTANDARD1_3 - if (FluentMapper.EntityMaps.TryGetValue(propertyInfo.DeclaringType, out entityMap)) + if (FluentMapper.EntityMaps.TryGetValue(propertyInfo.DeclaringType, out var entityMap)) #else - if (FluentMapper.EntityMaps.TryGetValue(propertyInfo.ReflectedType, out entityMap)) + if (FluentMapper.EntityMaps.TryGetValue(propertyInfo.ReflectedType, out var entityMap)) #endif { var mapping = entityMap as IDommelEntityMap; @@ -34,6 +33,22 @@ public string ResolveColumnName(PropertyInfo propertyInfo) } } } +#if NETSTANDARD1_3 + else if (FluentMapper.TypeConventions.TryGetValue(propertyInfo.DeclaringType, out var conventions)) + +#else + else if (FluentMapper.TypeConventions.TryGetValue(propertyInfo.ReflectedType, out var conventions)) +#endif + { + foreach (var convention in conventions) + { + var propertyMaps = convention.PropertyMaps.Where(m => m.PropertyInfo.Name == propertyInfo.Name).ToList(); + if (propertyMaps.Count == 1) + { + return propertyMaps[0].ColumnName; + } + } + } } return DommelMapper.Resolvers.Default.ColumnNameResolver.ResolveColumnName(propertyInfo); diff --git a/src/Dapper.FluentMap/Conventions/Convention.cs b/src/Dapper.FluentMap/Conventions/Convention.cs index feb66ca..c51d770 100644 --- a/src/Dapper.FluentMap/Conventions/Convention.cs +++ b/src/Dapper.FluentMap/Conventions/Convention.cs @@ -19,9 +19,15 @@ protected Convention() PropertyMaps = new List(); } - internal IList ConventionConfigurations { get; } + /// + /// Gets the convention configurations for the properties. + /// + public IList ConventionConfigurations { get; } - internal IList PropertyMaps { get; } + /// + /// Gets the property mappings. + /// + public IList PropertyMaps { get; } /// /// Configures a convention that applies on all properties of the entity. diff --git a/src/Dapper.FluentMap/Dapper.FluentMap.csproj b/src/Dapper.FluentMap/Dapper.FluentMap.csproj index af7fbaa..bfe721f 100644 --- a/src/Dapper.FluentMap/Dapper.FluentMap.csproj +++ b/src/Dapper.FluentMap/Dapper.FluentMap.csproj @@ -2,7 +2,7 @@ Simple API to fluently map POCO properties to database columns when using Dapper. Copyright © Henk Mollema 2017 - 1.8.0 + 1.8.1 Henk Mollema net451;netstandard1.3;netstandard2.0 true