Data is not inserting into DB, How handle composite primary key, where one PK is set to auto-increment. Here not entering any data into Id column , but it throws following exception .
"Cannot insert explicit value for identity column in table 'TableName' when IDENTITY_INSERT is set to OFF."
What I have tried:
Table
Id int primary key (auto increment)
SrNo varchar(6) primary key
Name varchar(10)
<pre lang="c#"> this.HasKey(m => new { m.Id, m.SrNo });
public bool Add(BusinessEntity mod)
{ _itemWarehouse.Insert(mod); }
taking data from WinForm where
Id=0 (didn't set, default), SrNo = X12 , Name = ABC
But not entering data into DB , throwing exception
"Cannot insert explicit value for identity column in table 'TableName' when IDENTITY_INSERT is set to OFF."