Dapper - have a different tablename than the name of your entity / class

Dapper will automatically look for a table with a name that matches your entity's name, however sometimes your entities do not match your tables. Perhaps you have some odd naming conventions, work with legacy tables or have some other reason. Dapper does not support this out of the box.

However there is a package - Dapper.Contrib which enables you to do this. This package extends dapper with some extra features, such as being able to set the table to map to via annotations:

[Table ("emps")]
public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Or change the name of the Primary key:

public class Employee
{
    [Key]
    public int EmployeeId { get; set; }
    public string Name { get; set; }
}

If you like Dapper.Contrib, I can also recommend SimpleCRUD which also has a lot of great features.

That is it!

Please let me know in the comments if you found this helpful!