Dapper sqlmapperextensions automatically adds “s” to tablename?

Deadly 提交于 2019-12-04 03:54:56
Dimitar Dimitrov

It seems that it's written this way, you can check the source code

Or more specifically:

private static string GetTableName(Type type)
{
    //.... codes

    if (TableNameMapper != null)
    {
        name = TableNameMapper(type);
    }
    else
    {
        var tableAttr = //.... lookup attribute
        if (tableAttr != null)
            name = tableAttr.Name;
        else
        {
            name = type.Name + "s";
            if (type.IsInterface() && name.StartsWith("I"))
                    name = name.Substring(1);
        }
    }

If you want to use the literal type name you can easily configure this.

SqlMapperExtensions.TableNameMapper = (type) => {
    //use exact name
    return type.Name;
};
Farzan Hajian

It is desgined this way. You can override the default behavior by decorating your POCO classes with Dapper.Contrib.Extensions.TableAttribute.

using Dapper.Contrib.Extensions;

[Table("Product")]
public class Product
{
...
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!