This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added column and key property resolver. Issue #12.
- Loading branch information
1 parent
1282626
commit 9e6c0b2
Showing
6 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Dapper.FluentMap.Dommel/FluentMapConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Dapper.FluentMap.Dommel/Resolvers/DommelColumnNameResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using Dapper.FluentMap.Dommel.Mapping; | ||
|
||
using DommelMapper = Dommel.Dommel; | ||
|
||
namespace Dapper.FluentMap.Dommel.Resolvers | ||
{ | ||
public class DommelColumnNameResolver : DommelMapper.IColumnNameResolver | ||
{ | ||
public string ResolveColumnName(PropertyInfo propertyInfo) | ||
{ | ||
var entityMap = FluentMapper.EntityMappers[propertyInfo.DeclaringType] as DommelEntityMap; | ||
|
||
if (entityMap == null) | ||
{ | ||
// todo: exception, null, fallback resolver or type.Name? | ||
throw new Exception(string.Format("Could not find the mapping for type '{0}'.", propertyInfo.DeclaringType.FullName)); | ||
} | ||
|
||
var propertyMaps = entityMap.PropertyMaps.Where(m => m.PropertyInfo.Name == propertyInfo.Name).ToList(); | ||
|
||
if (propertyMaps.Count == 0) | ||
{ | ||
return null; | ||
// todo | ||
} | ||
|
||
if (propertyMaps.Count > 1) | ||
{ | ||
// todo | ||
} | ||
|
||
return propertyMaps[0].ColumnName; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Dapper.FluentMap.Dommel/Resolvers/DommelKeyPropertyResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using Dapper.FluentMap.Dommel.Mapping; | ||
|
||
using DommelMapper = Dommel.Dommel; | ||
|
||
namespace Dapper.FluentMap.Dommel.Resolvers | ||
{ | ||
public class DommelKeyPropertyResolver : DommelMapper.IKeyPropertyResolver | ||
{ | ||
public PropertyInfo ResolveKeyProperty(Type type) | ||
{ | ||
var entityMap = FluentMapper.EntityMappers[type] as DommelEntityMap; | ||
if (entityMap == null) | ||
{ | ||
// todo: exception, null, fallback resolver or type.Name? | ||
throw new Exception(string.Format("Could not find the mapping for type '{0}'.", type.FullName)); | ||
} | ||
|
||
var keyPropertyMaps = entityMap.PropertyMaps.OfType<DommelPropertyMap>().Where(e => e.Key).ToList(); | ||
if (keyPropertyMaps.Count == 0) | ||
{ | ||
// todo: exception, null or fallback? | ||
throw new Exception(string.Format("Could not find the key property for type '{0}'.", type.FullName)); | ||
} | ||
|
||
if (keyPropertyMaps.Count > 1) | ||
{ | ||
// todo: exception, null or fallback? | ||
string msg = string.Format("Found multiple key properties on type '{0}'. This is not yet supported. The following key properties were found:{1}{2}", | ||
type.FullName, | ||
Environment.NewLine, | ||
string.Join(Environment.NewLine, keyPropertyMaps.Select(t => t.PropertyInfo.Name))); | ||
|
||
throw new Exception(msg); | ||
} | ||
|
||
return keyPropertyMaps[0].PropertyInfo; | ||
} | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
src/Dapper.FluentMap.Dommel/Resolvers/DommelTableNameResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters