Azure functions isolated NET 7 Unable to Add-Migration of Entity Framework Core

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

enter image description here

All necessary packages already installed.

Here is my project: Folder structure

enter image description here

DbContext

enter image description here

Add DbContext with correct connection string

enter image description here

Am I missing something else?

Thanks.

Upvotes: 4

Views: 732

Answers (1)

woozy
woozy

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

Related Questions