The OnConfiguring method provides a fall-back mechanism for configuring a DbContext in Entity Framework Core. In this section, Phil explains how this works, shows the scaffolded OnConfiguring method, and warns about possible side effects of using it in production code.
- [Instructor] We've already seen the OnConfiguring method.…That is how our context is configured…when we scaffolded the classes from…the adventure works database.…And this is essentially a fallback…configuration mechanism for a DbContext instance…that runs after construction.…And if the DbContext was configured through…the constructor, IsConfigured is set to true.…Be careful when using OnConfiguring…in production code,…'cuz this can introduce unexpected results.…
Typically, your OnConfiguring code will point…to your development database…or have some other settings in there…that you were testing with.…It is much better to use a design time…DbContext factory to set the configuration…and we'll cover that in the next section.…So, once again, here is the OnConfiguring method…and we talked about how it works.…Now I want to briefly mention when to use it.…So, it's great for testing…and we've been using it throughout this course.…
Not so great for production,…because if something should happen…with your dependency injection,…
- 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.