2
votes

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:

  • Entity Framework Core 3.1.0
  • Azure Functions v3 (.NET Core)

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:

  • Microsoft.EntityFrameworkCore.SqlServer (3.1.0)
  • Microsoft.EntityFrameworkCore.Tools (3.1.0)

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?

2

2 Answers

2
votes

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.

-1
votes

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.