Reputation: 83
I'm trying to connect Azure Functions (Isolated) with EF Core 7.0.1 using NET 7.
Add-Migration throw an error: Unable to create an object of type 'MyDbContext'.
Error descriptions
All necessary packages already installed.
Here is my project: Folder structure
DbContext
Add DbContext
with correct connection string
Am I missing something else?
Thanks.
Upvotes: 4
Views: 732
Reputation: 33
Database Migrations happen at Design-Time, not at Runtime. So you have to provide your IDE with a way to create a DbContext
without starting the actual function. One way would be to implement a Design Time Factory as described in the Official Documentation. With that class created, the command Add-Migration
automatically finds that class and executes CreateDbContext
, which then provides the context for the migration.
Upvotes: 1