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 586 forks source link

Dapper SetTypeMap Breaks ClassMapper #184

Open danielearrighi opened 6 years ago

danielearrighi commented 6 years ago

Hello, In my project I'm using a custom SqlMapper to map my Db columns in dapper, but when I setup Dapper to user my custom type mapper by doing: Dapper.SqlMapper.SetTypeMap(typeof(User), new UserMapper()); Suddently, DapperExtension is no more able to Map my User class so that when I do: User item = cn.Get<User>(id); The item contains only default values.

My UserMapper does not interfere with ClassMapper implementation from DapperExtensions.

Any suggestion? Thank you for your help

danielearrighi commented 6 years ago

After a further investigation, I've finally found and solved the problem: Say I have a TestClass with property Id mapped in my UserMapper to the database column UserId.

Solved by checking if the search for a IPropertyMap with ColumnName = Id fails; if so, I fallback by searching for an IPropertyMap with Name = Id.

If you think this can be solved in a better way, please let me know Thanks!

valfrid-ly commented 3 years ago

Could you design an unit test for this particular case so I can put it to be validated ?

Thanks