The Entity Framework Core tooling command must be able to create an instance of the DbContext. This can be done with a parameterless constructor and the OnConfiguring method, but that is at odds with ASP.NET Core'2 DbContextPool. A better way is to use a DbContextDesignTimeFactory. In this section, Phil explains what that is and demonstrates the creation of the factory for this project.
- [Narrator] Design Time configuration…is often different than Run Time Configuration.…This is one of the reasons why I don't like using…the OnConfiguring in my production apps.…EF Core Tools need an instance…of the application's DbContext.…Which means, it has to be configured.…With providers and connection strings…and all the information that we've seen so far.…In ASP.NET Core, this is very very simple.…Simply use the ASP.NET Core app as the startup project…and you get the benefits of all…of the ASP.Net Core configuration.…
In other applications, you can use…a parameterless constructor with OnConfiguring,…which breaks DbContext pulling an ASP.NET Core,…but again, we're talking about other applications.…Or you can use a design time DbContext Factory.…That's my preferred method.…And the way you create a design time DbContext Factory,…is you create a class that implements, surprisingly enough,…the IDesignTimeDbContextFactory interface…that takes the type of your context.…
The interface has a single method, CreateDbContext.…
- 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.