Repository.Delete requires a SaveChanges
See original GitHub issueRelated Documentation:
https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#automatically-saving-changes
There is an inconsistency with regards to Updating and Deleting an entity.
This is off the latest MVC sample download.
To make a simple example, I just modified the user delete function to also change the name too, to demostrate my point.
Editing a property seems to instantly update it, even if I “re-get” the entity. However, deleting the entity does not instantly update it, as you can see in the image.
Shouldn’t these two things be consistent? Either an update also requires a SaveChanges
, or the Delete does not require a SaveChanges
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (19 by maintainers)
Top Results From Across the Web
Delete needs to Read first in Repository Pattern?
Data.Entity.EntityState.Deleted; db.SaveChanges();. This way you do one less read, on top of that take a look at components ...
Read more >Deleting data via the DbContext
When SaveChanges is called, a DELETE statement is generated and executed by the database. exec sp_executesql N'SET NOCOUNT ON;; DELETE FROM [ ...
Read more >Basic SaveChanges - EF Core
SaveChanges () is one of two techniques for saving changes to the database with EF. With this method, you perform one or more...
Read more >Cascade Delete - EF Core
Cascading deletes are needed when a dependent/child entity can no longer be associated with its current principal/parent.
Read more >EF Core Bulk Delete | Optimize Data ...
The SaveChanges performs one database round-trip for every entity to delete. So, if you need to delete 10,000 entities, 10,000 database ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In unit test, there is no outer unit of work, so
SaveChanges
is called whenUnitOfWorkInterceptor
completes the unit of work.https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#conventional-unit-of-work-methods
When updating, you already changed the field values fore calling Update method. For delete and create (for generating Id value for example), SaveChanges must be called.