In this section, Phil shows the SaveChanges method, demonstrating auto update of a state and the option to manually update EntityState.
- [Instructor] The final two tests,…ShouldResetStateOfEntitiesAfterSaveChange…and ShouldManuallyResetStateOfEntitiesAfterSaveChange,…we're going to use a transaction…so we don't dirty the database.…And don't worry about the syntax,…we will cover this in great detail in the next section.…And the transaction comes off of the database.…
To make sure, we'll do transaction.Rollback,…and what we want to do is change a record.…You already have code for that…so let's plug that right in here.…And then the difference here is we will call SaveChanges.…Then what we want to assert is that the EntityState…is now Unchanged.…
So the default SaveChanges method,…as I've mentioned in the slide deck,…resets all of the entity states to Unchanged.…But that can also be controlled so you can do it manually.…So let's change this.…I'm copying the entire test down but what I want…to do here is pass in true.…There's one parameter in SaveChanges,…and let's see what IntelliSense shows us.…
AcceptAllChanges, and by default that is true.…So let's put a false in there…
- Persisting data
- Tracking EntityState
- Configuring the DbContext
- Transactions across DbContexts
- Understanding the batching process
- Attaching and deleting detached entities
- Design time configuration
- Concurrency checking
- Using custom execution strategies
Skill Level Intermediate
1. Persisting Data: Part 1
2. Persisting Data: Part 2
3. DbContext Options and Configuration
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.