I have a service method like this:
[OperationContract]
public void CreateIcd9(int icd9ID, string code, string description, string specialty)
{
var count = from icd in clogicEntities.ICD9
where icd.ID == icd9ID
select icd;
if (count.Count() >= 1)
{
var icd9 = clogicEntities.ICD9.Where(icd => (icd.ID == icd9ID)).SingleOrDefault();
if (icd9 != null)
{
icd9.CODE = code;
icd9.DESCRIPTION = description;
icd9.SPECIALTY = specialty;
}
}
else
{
ICD9 icdNew = new ICD9()
{
ID = icd9ID,
CODE = code,
DESCRIPTION = description,
SPECIALTY = specialty
};
// Insert Icd9
clogicEntities.ICD9.AddObject(icdNew);
}
clogicEntities.SaveChanges();
}
Everything is ok until today, i got a exception when call this method with icd9ID = 1992401733
i got this exception:
An error occurred while updating the entries.
See the inner exception for details. ----> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'ID', table '1224-CLOGIC.dbo.ICD9'; column does not allow nulls. INSERT fails.
The statement has been terminated
I try to reproduce this issue but no luck, i wonder it’s MAX Int problem:
2147483647 – MAX Int
1992401733 – My value
Please help me.
i found my problem is the ICD9 table on EF with ID(pk) Identity(1,1) but on SQL ICD9 table – ID(pk) Identity = false so when
it just pass 3 values (Code, Description, Specialty) without ID to SQL.
And reason why i passed 0 int value to service is i forgot update service reference after change parameter.
Regards.