Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Error when update item

$
0
0

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


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>