I use Entity Framework 4.0. Is it possible that SaveChanges()
returns 0 but doesn't throw an exception? For example, after adding.
Here is my code:
try { _context.CodeProducts.Add(entity); _context.SaveChanges(); //Shell I control return result from SaveChanges() in here. //However doesn't throw an exceoption? return new MethodResponse() { ResultText = "Successful", Type = MethodResponse.ResponseType.Succeed }; } catch (OptimisticConcurrencyException exc) { throw exc; } catch (UpdateException exc) { throw exc; } catch (Exception exc) { throw exc; }
According to the documentation, the return value of DbContext.SaveChanges
is
The number of objects written to the underlying database.
So what you see is only possible, when no entities needed to be saved to the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With