我有一个表,其主键由两列组成,这两列都不是自动递增的,而且我的 Dapper 插入(Dapper 扩展的一部分)在插入时失败,说两列中的第一列不允许 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”中;列不允许空值。插入失败。
出于某种原因,Dapper 没有得到StudentId
值为 5 的值。我是否必须为组合了 PK 的表或具有非自动递增 PK 的表做一些特别的事情?谢谢。