Dapper Extensions - change primary key field

dapper

Question

We are thinking of switching over to Dapper from EF. I'd like to use the Dapper Extensions to populate my entities like:

UserInstance = conn.Get(UserProfile)(RecordID)

All of our primary key columns are named RecordID but preceeded by Parent_RecordID. The Get tries to use Parent_RecordID as my primary key column, "If multiple properties end with Id, Dapper Extensions will use the first Id property as the primary key."

How can I change this so it looks for RecordID as my primary key only for every table? I understand I can create my own mapper for entity but I want this change to apply to every table(there are 100's of them) and would rather not create a mapper for every one of them.

Popular Answer

Have you tried creating a mapping class for the entity?

public class UserProfileMapper : ClassMapper<UserProfile>
{
    public UserProfileMapper()
    {
    Table("UserProfile");
    Map(f => f.RecordID).Key(KeyType.Identity);
    ...
    }
}

Not sure if the mapper class is used for a Get.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why