Hello everyone,
i have a piece of code where i try to update an item :
public void Update(ItemBox itemBox)
{
try {
context.ItemBox.Update(itemBox );
context.SaveChanges();
}
catch(Exception ex) {
// here my error message is:
// Violation of UNIQUE KEY constraint 'ItemBox_Number'. Cannot insert duplicate key in object 'ItemBox'.
// The duplicate key value is (123hjjj-321hjjj).
}
}my table if ItemBox have four columns:
Id PK int, not null
OfficeId FK int, not null
Number nvarchar(max), not null
ItemBoxType FK int, null
IsExist bit, not null
I would to update IsExist flag for a specific item and set property to false, i pass the item with all field filled, and when update and i get the error:
"Violation of UNIQUE KEY constraint 'ItemBox_Number'. Cannot insert duplicate key in object 'ItemBox'."
" The duplicate key value is (123hjjj-321hjjj)."
in my specific item of ItemBox i have in number field this value '123hjjj-321hjjj'
I dont understand why.
Thanks for the help