In this section, Phil demonstrates attaching detached entities through entity operations.
- [Instructor] With the basic save test,…we covered a lot of the scenarios…with Add, Update and Remove when working with new…or detached entries.…But we didn't cover the Attach command.…So let's do that now.…So let me copy in the code.…So I create a new product…that is not in the database.…When I call Attach on that,…the primary key of product id is blank,…so the EntityState is set to added.…
What I do next is actually detach it…from the ChangeTracker,…so I don't have to keep creating new products…to show what I'm demonstrating.…And just like the Add, Update and Remove…I can call Attach either on the context or the dbset,…and I get the same result.…I am going to add in another Detached command here.…The one update scenario that I did not cover…in the basic save test…is when you call Update on a brand new entity.…
Here on line 37, we're confirming that…because there is not a primary key,…it is added to the ChangeTracker in an Added state.…And then once again I detach it to reset…the state of the entity.…Then here I am showing that if you call Remove…
- 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
Entity Framework Core Essential Training: 1with Phil Japikse3h 20m Intermediate
ASP.NET Core: Test-Driven Developmentwith Richard Rout37m 30s 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.