どちらも自動インクリメントではない 2 つの列で構成される主キーを持つテーブルがあり、Dapper 挿入 (Dapper 拡張機能の一部) が失敗し、2 つの列の最初の列では null が許可されないというメッセージが表示されます。 、私が渡している値はnullではありません。
表Student
:
StudentId (PK, not null) \_ (combined to form primary key)
StudentName (PK, not null) /
Active -- just another column
C#:
public class Student {
public int StudentId { get; set; }
public string StudentName { get; set; }
public bool Active { get; set; }
}
var newStudent = new Student { StudentId = 5, StudentName = "Joe", Active = true };
var insertSuccess = myConn.Insert<Student>(newStudent);
エラー:
値 NULL を列 'StudentId'、テーブル 'dbo.Student' に挿入できません。列はヌルを許可しません。INSERT は失敗します。
Dapper は何らかの理由で 5 の値を取得できません。PK を組み合わせたテーブル、または自動インクリメントされていないStudentId
PK を持つテーブルに対して何か特別なことをする必要がありますか? ありがとう。