context.SaveChanges returns 0 if i only hit the update button. If i dont change anything and just hit the update button, it return me 0. I am checking on the value which is returned by savechanges. Which are the conditions where savechanges returns me 0. What are the return values indicate.?
Following is my code.
int returnValue = CS.SaveChanges();
return returnValue == 1 ? "User profile has been updated successfully" : "Unable to update";
According to the documentation the return value is the number of objects updated in the context:
Return Value
Type: System.Int32
The number of objects written to the underlying database.
So your method could look like this:
int returnValue = CS.SaveChanges();
return returnValue > 0 ?
String.Format("{0} User profiles have been updated successfully.", returnvalue) :
"No updates have been written to the database.";