Dapper use singular table name

前端 未结 2 2013
北荒
北荒 2021-01-11 09:38

I experimented with Dapper and Dapper.Contrib. I have the following class:

public class Customer
{
    public int Id { get; set; }
    public string FirstNam         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-11 09:53

    Dapper.Contrib supports the Table attribute. Use it to manually specify the name of the table that an entity uses. See the docs for further information.

    Alternatively there is a static delegate on SqlMapperExtensions called TableNameMapper. You can replace this with an implementation that performs the pluralization. PluralizationService in the framework can help you here.

    It is used as follows:

    SqlMapperExtensions.TableNameMapper = (type) => {
        // do something here to pluralize the name of the type
        return type.Name;
    };
    

提交回复
热议问题