henkmollema / Dapper-FluentMap

Provides a simple API to fluently map POCO properties to database columns when using Dapper.
MIT License
427 stars 86 forks source link

Question about mapping attributes #86

Closed pauldendulk closed 5 years ago

pauldendulk commented 5 years ago

Hi, I am currently looking for the simplest way to do column mapping in Dapper. Your introduction page mentions 'mapping attributes'. Does Dapper support some kind of column mapping at all? I could not find it so far.

henkmollema commented 5 years ago

AFAIK Dapper does not support attribute mapping out of the box. It's pretty simple to add one to your application though. You can check out the implementation I use in Dommel (a small ORM library on top of Dapper): https://github.com/henkmollema/Dommel/blob/3aef41f139a785ab73b7a92aa3eef2e5627947d9/src/Dommel/DommelMapper.DapperTypeMap.cs

pauldendulk commented 5 years ago

Thanks for you answer. The link to your implementation is very helpful.

I also tried FluentMap for mapping. The configuration is simple and powerful but I don't understand how it should be hooked into Dapper. It did not work for me when using Dapper.Contrib's Insert method. Should it work with that? Or does it only apply to Dapper core? If so, how? Or do i need to use Dommel to take advantage of FluentMap?

henkmollema commented 5 years ago

By default FluentMap only hooks into the type mapping of just Dapper. Other ORMs on top of Dapper usually have their own implementation to figure out the table/column names of your entities. For instance, they might utilize attribute mapping (like Dommel does) or provide their own mapping configuration.

In the case of Dommel there is a FluentMap extension which hooks into the extensibility points of Dommel to map table and column names based on the FluentMap configuration. You can find this extension in this repository and on NuGet (https://www.nuget.org/packages/Dapper.FluentMap.Dommel) as well.

pauldendulk commented 5 years ago

ah, I see. The fact that Dommel was mentioned on the introduction page initially confused me. What would have helped me is some examples of Dapper calls that make use of FluentMap. So, they would first show how to configure FluentMap, and perhaps explain the problem they solve, and then add some examples of Dapper calls that use these configurations.

I now see that Dapper.FluentMap.Dommel is part of this same repository, so I understand why Dommel is mentioned.