Dapper Contrib 插入 MatchNamesWithUnderscores 映射器不工作

Dapper Contrib Insert MatchNamesWithUnderscores mapper isn’t working

Dapper.DefaultTypeMap.MatchNamesWithUnderscores 不适用于插入。映射器适用于 Get<> 方法。我在我的 ASP.NET Core 1.0 RC2 项目中使用以下版本以及 postgres 数据库。

"dependencies": {
    "Dapper": "1.50.0-rc2",
    "Dapper.Contrib": "1.50.0-beta8"
}

代码片段

using (var conn = new NpgsqlConnection("connString"))
{
    conn.Open();
    Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
    long id = conn.Insert(new Foo { Name = "new foo", LocationId = 3});

    return id;
}

执行的插入SQL语句

insert into foo ("Name", "LocationId") values (, ) RETURNING Id

富class

[Dapper.Contrib.Extensions.Table("foo")]
public class Foo
{
    public int Id { get; set; }
    public string Name { get; set; }            
    public int LocationId { get; set; }
}

富table

CREATE TABLE "foo" (
    "id" SERIAL PRIMARY KEY,
    "name" VARCHAR(100) NOT NULL,
    "location_id" INTEGER REFERENCES "location" (id)
);

Dapper.Contrib 执行插入,看起来 Dapper.Contrib 甚至没有引用 MatchNamesWithUnderscores。你可以在 dapper 的 github 上打开一个问题,但它看起来不容易改变。

There the open issue on github