Stephan Smit
Stephan Smit

Reputation: 97

How do I use Entity Framework Core in Azure Functions

I am trying to make a simple Web API with Azure Functions (Http trigger).
In my function I want to access a SQL Server Database.
I would like to retrieve my data from the database using Entity Framework Core.
I would prefer to to use the newest versions available at the time of posting this:

I have an existing database, therefor I want to do reverse engineering using the Scaffold-DbContext command.
In order to do this I have added the following packages to my Azure Functions v3 project created in Visual Studio:

When running the Scaffold-DbContext command in the Package Manager Console I get the following error:

enter image description here

What am I doing wrong?
What can I do to fix this?

Upvotes: 2

Views: 3216

Answers (2)

Stephan Smit
Stephan Smit

Reputation: 97

I found the solution to the problem.

When the project is build the project dll gets generated to the bin\Debug\netcoreapp3.0\bin folder but when you try and run the Scaffold-DbContext command it looks for it in the bin\Debug\netcoreapp3.0 folder.

Solution. Just copy the project dll to that folder and then it works.

Upvotes: 2

suziki
suziki

Reputation: 14080

For thr error, try to add

<PropertyGroup>               
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>

to your .csproj file. Test whether it can be solved.

If it doesn't work, please try to create a new project under the same solution and ran the entity framework commands in that project. That should work. Then import this project to your first project, this seems an issue with azure-function.

Upvotes: -1

Related Questions