When working with function apps, you may want to connect SQL Server to allow for using an API with data persistence.
Setting up Project to Use Entity Framework
Add the following to your
.csproj file, in the section with
And then add the following to allow for copying the project DLL (supports builds in both Windows and Linux):
For setting this up, I’d recommend having at least one Model ready for use. In our case, let’s use a simple example with
Now create the
ContextFactory.cs files in the Models folder:
Now create a
Startup.cs file in root:
Setting up Database
Finally, you’ll need to set up a database for use. Create the database and use the connection string – let’s use SQL Server locally and set this in the Azure Function project’s
Once this is set, setting up migrations is the next step. Set the environment variable on your PC:
With this step done, start the application and check to see if your database was updated correctly, and that you can see the tables desired.