stevo
stevo

Reputation: 2284

Dapper Contrib Insert MatchNamesWithUnderscores mapper isn’t working

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)
);

Upvotes: 2

Views: 8108

Answers (2)

stevo
stevo

Reputation: 2284

There the open issue on github

Upvotes: 1

Lloyd Stockman
Lloyd Stockman

Reputation: 79

Dapper.Contrib does the insert and it looks like Dapper.Contrib doesn't even reference MatchNamesWithUnderscores. You can open an issue on dapper's github maybe but it doesn't look easy to change.

Upvotes: 2

Related Questions