我正在关注使用 Entity Framework Core 和 SQL Server 的 InsertOrUpdate 文章。
http://blog.linq2db.com/2015/05/linq-crud-operations.html
所以我的 linq2db 查询与他们的文档相同。
using (var db = new DataConnection())
{
db.GetTable<TestTable3>()
.InsertOrUpdate(
() => new TestTable3
{
ID = 5,
Name = "Crazy Frog",
},
t => new TestTable3
{
Name = "Crazy Frog IV",
});
}
但在我的情况下Id
是自动递增的身份主列。所以我收到如下错误。
System.Data.SqlClient.SqlException: 'Cannot insert explicit value for identity column in table 'TestTable3' when IDENTITY_INSERT is set to OFF.'
现在我知道无法提供身份列。但是如果我不提供,那么它会抛出错误
LinqToDB.Linq.LinqException: 'InsertOrUpdate method requires the 'TestTable3.Id' field to be included in the insert setter.'