Reputation: 181
I'm using Dapper.Contrib v1.50.0 and Dapper v1.50.2. I have the key property in the class annotated with [Key], and in the database the column is Identity. When I try to Insert Sql Server is throwing an error that value can not be inserted into an Identity column. Does Dapper.Contrib support inserts to tables that use Identity columns?
public class Product {
[Key]
public int ProductId {get; set;}
public string BrandCode { get; set; }
public bool TwoDScanRequired {get; set;}
public string CommodityCode {get; set;}
public string Description {get; set;}
}
Upvotes: 1
Views: 1108
Reputation: 2508
Changing primary key from [System.ComponentModel.DataAnnotations.Key] to [Dapper.Contrib.Extensions.Key], solved it!
Upvotes: 0
Reputation: 181
I realized that I accepted the default using System.Component.Model.DataAnnotations, it should have been using Dapper
Upvotes: 1