question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repository.Delete requires a SaveChanges

See original GitHub issue

Related Documentation:
https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#automatically-saving-changes

There is an inconsistency with regards to Updating and Deleting an entity.

image

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:closed
  • Created 3 years ago
  • Comments:22 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Feb 18, 2021

In unit test, there is no outer unit of work, so SaveChanges is called when UnitOfWorkInterceptor completes the unit of work.

https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#conventional-unit-of-work-methods

0reactions
ismcagdascommented, Mar 30, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found