I have a table with name MyTable
in my database. A POCO class MyTablePoco
is created for that table.
Following is Mapping code of Dapper Extensions:
class MyTableMapper : ClassMapper<MyTablePoco>
{
public MyTableMapper()
{
Table("MyTable");
AutoMap();
}
}
Following is the code where I need table name from POCO class:
private string GetTableName<T>()
{
return typeof(T).Name.Replace("Poco", "");
}
My convention for naming POCO classes is TableName + "Poco"
. Based on this convention, my hack of replacing "Poco" from class name works great as shown in above example.
But, I would like to get the table name from mapping configurations instead. I think this will be more reliable as it avoids any string handling and assumptions about naming POCOs.
How can I get table name from POCO class with Dapper Extensions mappings?