I am trying out Dapper. I like what I have seen so far. In order to do simple CRUD, I use Dapper.rainbow. It works very well. However, it works only if the table has identity column with name Id. It makes sense to have db like that but I can not ask for column name change in database just to use Dapper. To be more clear, I am working with database like Northwind Db. It has tablename repeated in Id column everywhere.
In order to handle this,I changed the Dapper.Rainbow code as below:
public T Get(TId id,string idColumnName="Id")
{
return database.Query<T>("select * from " + TableName + " where "+idColumnName+" = @id", new { id }).FirstOrDefault();
}
Is there a better way to handle this such as Column mapping /annotations or something completely different?
I have read questions like these
Manually Map column names with class properties
Dapper.Rainbow VS Dapper.Contrib
( I came across similar little problem with Dapper.Contrib, I will ask it separately).
Update - Not sure if the answers are applicable to my Dapper.Rainbow problem here (Atleast, I don't see how).
Thanks for help in advance!