In Entity Framework, see whether an insert or update was successful.

entity-framework savechanges

Question

ExecuteNonQuery() in ADO.NET returns the amount of rows impacted by the command for UPDATE, INSERT, and DELETE statements. (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx)

context in EF v1. "The number of objects in an Added, Modified, or Deleted state when SaveChanges was called," is what the SaveChanges() function returns. (http://msdn.microsoft.com/en-us/library/bb739065.aspx)

When many entities (or a single entity) are added to the context or changed, do let us know. How to determine if an actual INSERT or UPDATE was successful when the SaveChanges() function is used.

Can we presume that an INSERT or UPDATE was successful if there was NO exception?

Many thanks

1
7
2/8/2017 9:00:51 PM

Accepted Answer

Yes, you may presume that the statements were correctly performed if there is no exception.

13
8/25/2009 10:52:23 PM

Popular Answer

Although it may not be a direct response, this information could be useful. By default, when the SaveChanges function is used, all instructions are included in a single DbTransaction (Programming Entity Framework, Julia Lerman). Therefore, either none or all orders will be effectively carried out. That is one method of determining if an insert, update, or delete was successful.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow