The Dapper.DefaultTypeMap.MatchNamesWithUnderscores
isn’t working for inserts. The mapper works fine for the Get<>
method. I'm using the follow versions in my ASP.NET Core 1.0 RC2 project together with postgres database.
"dependencies": {
"Dapper": "1.50.0-rc2",
"Dapper.Contrib": "1.50.0-beta8"
}
Code snippet
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;
}
The executed insert 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)
);