The first time I Edit a Record , the result would be Successful. but for the second time that i want to edit that record , it fails this is the error message
"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."
I traced the program. when i am reading the object
ListViewItem item = new ListViewItem(cableApplication.Id.ToString());
item.SubItems.Add(cableApplication.Application);
item.SubItems.Add(cableApplication.DefaultSize.ToString());
item.SubItems.Add(ASCIIEncoding.ASCII.GetString(cableApplication.tstamp));
listView1.Items.Add(item);
i watch the value of the cableApplication.tstampin watch window, item.SubItems.Add(cableApplication.Application);
item.SubItems.Add(cableApplication.DefaultSize.ToString());
item.SubItems.Add(ASCIIEncoding.ASCII.GetString(cableApplication.tstamp));
listView1.Items.Add(item);
it is byte[8] :0,0,0,0,0,0,18,178
again in the watch window i convert tstamp into string and then byte[], the value of tstamp changes
Encoding.ASCII.GetBytes(ASCIIEncoding.ASCII.GetString(cableApplication.ts)) it gives me :0,0,0,0,0,0,18,63
so definately i'll get the error message because the value of tstamp has changed
but for the first time that i edit the record but value are equal , so it is possible to edit the record,
any help is appreciated about time stamp
thank you
Jaganathan BantheswaranPosted Oct 9, 2013, 1:56 AM
nnmmPosted Oct 8, 2013, 6:05 AM
suppose the entity is populating in listview item.SubItems.Add(ASCIIEncoding.ASCII.GetString(cableApplication.ts));
and there is a breakpoint on above sentence. excatly in this line i am checking the value of ts in watch window. i haven't gone any further that cause me update the record in other procedure, in item.SubItems.Add(ASCIIEncoding.ASCII.GetString(cableApplication.ts)); there is breakpoint to i checked the
ASCIIEncoding.ASCII.GetString(cableApplication.tstamp) , it is byte[8] :0,0,0,0,0,0,18,178, without moving any further ( i mean breakpoint is above sentence) i check the value for
Encoding.ASCII.GetBytes(ASCIIEncoding.ASCII.GetString(cableApplication.ts))
it is 0,0,0,0,0,0,18,63
and also i have not any refresh method in my context
thank you for your attention
Jaganathan BantheswaranPosted Oct 8, 2013, 4:32 AM
This is bcaz of concurrency update. You're actually updating the data yourself in another method in-between the select and the update.
Make sure the selecting record is done before updating the Records.
Or try like this
try {
context.SaveChanges();
}
catch (OptimisticConcurrencyException)
{
context.Refresh(RefreshMode.ClientWins, entity name here);
context.SaveChanges();
}