Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Add conventions to the Dommel column name resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
henkmollema committed May 5, 2020
1 parent af01c71 commit d1dbad8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Dapper.FluentMap.Dommel/Dapper.FluentMap.Dommel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>Dapper.FluentMap extension for Dommel support.</Description>
<Copyright>Copyright © Henk Mollema 2017</Copyright>
<VersionPrefix>1.7.0</VersionPrefix>
<VersionPrefix>1.7.1</VersionPrefix>
<Authors>Henk Mollema</Authors>
<TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
21 changes: 18 additions & 3 deletions src/Dapper.FluentMap.Dommel/Resolvers/DommelColumnNameResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions src/Dapper.FluentMap/Conventions/Convention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ protected Convention()
PropertyMaps = new List<PropertyMap>();
}

internal IList<PropertyConventionConfiguration> ConventionConfigurations { get; }
/// <summary>
/// Gets the convention configurations for the properties.
/// </summary>
public IList<PropertyConventionConfiguration> ConventionConfigurations { get; }

internal IList<PropertyMap> PropertyMaps { get; }
/// <summary>
/// Gets the property mappings.
/// </summary>
public IList<PropertyMap> PropertyMaps { get; }

/// <summary>
/// Configures a convention that applies on all properties of the entity.
Expand Down
2 changes: 1 addition & 1 deletion src/Dapper.FluentMap/Dapper.FluentMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>Simple API to fluently map POCO properties to database columns when using Dapper.</Description>
<Copyright>Copyright © Henk Mollema 2017</Copyright>
<VersionPrefix>1.8.0</VersionPrefix>
<VersionPrefix>1.8.1</VersionPrefix>
<Authors>Henk Mollema</Authors>
<TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down

0 comments on commit d1dbad8

Please sign in to comment.