Entity Framework: Store update insert or delete statement affected an unexpected number of rows (0)

NishaNinja
 
on Jul 26, 2014 12:18 AM
11498 Views

hi,

im following bellow code to update an entity model. But i got following eroor. : Store update, insert, or delete statement affected an unexpected number of rows (0)

And reason of this error is also known, it's only due to-that property does not exist in database. For that i found have only one option : first check that entity exist or not, then update it.

But, as i'm updating 10,000+ rows at a time, it will be time consuming to check each time in database if this property exist or not.

Is there any another way to solve this ?

Thank you.

foreach (Property item in listProperties)
               {
                   db.Properties.Attach(item);
                   db.Entry(item).Property(x => x.pState).IsModified = true;
               }
               db.SaveChanges();

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Azim
 
on Jul 26, 2014 12:59 AM

Then you need to check it 1000 times in code if you are updating 1000 records.