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 stetement
insert into foo ("Name", "LocationId") values ($1, $2) RETURNING Id
Foo class
[Dapper.Contrib.Extensions.Table("foo")]
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
public int LocationId { get; set; }
}
Foo table
CREATE TABLE "foo" (
"id" SERIAL PRIMARY KEY,
"name" VARCHAR(100) NOT NULL,
"location_id" INTEGER REFERENCES "location" (id)
);
答案 0 :(得分:1)
Dapper.Contrib执行插入操作,看起来Dapper.Contrib甚至没有引用MatchNamesWithUnderscores。你可以在dapper的github上打开一个问题,但它看起来不容易改变。
答案 1 :(得分:0)