2

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 ($1, $2) RETURNING Id

フークラス

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

フーテーブル

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

2 に答える 2

1

Dapper.Contrib は挿入を行い、Dapper.Contrib は MatchNamesWithUnderscores を参照していないようです。dapper の github でイシューを開くこともできますが、変更するのは簡単ではないようです。

于 2016-06-08T00:58:26.960 に答える
1

githubに未解決の問題があります

于 2016-06-08T04:48:22.817 に答える