The AddOrUpdate method in Entity Framework 6 enabled Upsert operations, where a record was added if its unique identity was not found, and an update if it was. This method is not yet in Entity Framework Core. In this section, Phil shows how to recreate the AddOrUpdate method for EF Core.
- [Narrator] EF 6 has an AddOrUpdate method on the DbSet.…This adds a new record if the unique identifier isn't found…and updates the record if it is.…Now this unique identifier can be anything,…it doesn't have to be the primary key.…And while the EF Core Team has AddOrUpdate on it's backlog,…it is not yet been implemented.…There is an example in the MusicStore sample application,…that is maintained by Microsoft and the EF Core…and acep.net Core teams,…but that implementation is entirely client side.…
What we want to be able to do is an AddOrUpdate…that executes server side.…So let's see how that works.…Before we get into the code that…actually does the AddOrUpdate, also known as an upsert,…let's look at how we would use the code.…So if we have a new record, it should insert it,…if we have an existing record it should update it.…So let's create a new record.…
So product equals TestHelpers.CreateProduct,…and then contest.product.AddOrUpdate the product,…and then the property we want to use…as a unique identifier, in this case, name.…
- Entity Framework Core components and projects
- Working with scaffolded files
- Testing with xUnit
- Viewing generated SQL
- Composing queries
- Sorting and filtering results
- Working with aggregates
- Loading related data
- Logging and tracking
- Mapping functions
- Generics and delegates
- Checking concurrency
- Resiliency and transactions
Skill Level Intermediate
Learning Entity Framework Corewith Reynald Adolphe1h 35m Intermediate
1. Get to Know Entity Framework
2. Set the Stage
3. Querying Data: Part 1
4. Querying Data: Part 2
5. Advanced Query Features
6. Persisting Data
7. DbContext Options and Configuration
Thank you1m 23s
- 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.