Skip to content
pagebrooks edited this page Dec 8, 2011 · 11 revisions

Out of the box, Dapper Extensions has a default ClassMapper (AutoClassMapper) that handles the population of POCOs. The ClassMapper facility is important because it is what allows us to keep the POCOs attribute free. You can easily change the behavior of Dapper Extensions, by supplying your own implementation of ClassMapper.

DapperExtensions.DapperExtensions.DefaultMapper = typeof(MyCustomClassMapper<>);

AutoClassMapper Assumptions

The default AutoClassMapper makes certain assumptions about your database schema and POCOs.

  • AutoClassMapper assumes that your table names are singular (Ex: Car table name and Car POCO name).
  • Each POCO has at least one property named Id or ends with Id.
  • If multiple properties end with Id, Dapper Extensions will use the first Id property as the primary key.
  • If the Id property is determined to be an Integer, the KeyType will be set to Identity.
  • If the Id property is determined to be a Guid, the KeyType will be set to Guid.
  • If the id property is anything other than an Integer our Guid, the KeyType will be set to Assigned.

PluralizedAutoClassMapper

The AutoClassMapper assumes that your database table names are singular (Ex: Car table instead of Cars). Since it is such a common request, we have included a ClassMapper (PluralizedAutoClassMapper) that will pluralize any references to table names. To configure Dapper Extensions with the PluralizedAutoClassMapper, simply include the following code at startup:

DapperExtensions.DapperExtensions.DefaultMapper = typeof(PlurizedAutoClassMapper<>);
Clone this wiki locally