tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.
1.79k stars 584 forks source link

Request: Custom convention-based mapping #99

Open mitchmchenry opened 9 years ago

mitchmchenry commented 9 years ago

The manual mapping option is great, but it would be really nice to be able to create custom mapping conventions rather than always having to create a manual map for every class the automapper can't handle by default.

I know you can also implement your own ClassMapper, but the fact that default conventions are combined with other logic (like the "KeyMap" logic in ClasMapper.AutoMap) makes it hard to just override the default convention without having to re-implement all the other logic too.

Something like the custom resolvers in Dommel would be ideal. But even something as simple moving the "CanMap" and "KeyMap" logic out of the ClassMapper.AutoMap code and into their own methods that could more easily be overridden would make customizing a lot easier.

Just like it's simple to customize table name resolution by overriding ClassMapper.Table(), you could have ClassMapper.IsKey() & CanMap(). That way global conventions on table names, key names & mapping exclusions would be simple to implement by just inheriting from ClassMapper and overriding one or more of those methods.. I think that would be a quick code change and shouldn't break existing code.

deluvas commented 9 years ago

+1

valfrid-ly commented 3 years ago

I'd like to understand it better. As I see, canMap is a user function and it can be defined anywhere in your code. If it's not null will return basically the properties that should be mapped by Automap.

I did like the Dommel resolver but I not understanting how to implement it.