Using Entity Framework with Azure Functions

Jeff Hollan
May 28 · 4 min read

Adding entity framework to a function project

Update-Package Microsoft.NET.Sdk.Functions Install-Package Microsoft.Azure.Functions.Extensions
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.2.3
Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.2.3 Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.2.3

Add the entity models

Write the function code to inject the entity context

Enable design-time DbContext creation

Getting the project .dll in the right spot

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)bin\$(ProjectName).dll&quot; &quot;$(TargetDir)$(ProjectName).dll&quot;" />

Adding an entity framework migration

$env:SqlConnectionString= "Server=tcp:mySqlServerStuffxxx" Add-Migration InitialCreate Update-Database

Writing the function app and publishing

Jeff Hollan

Written by

Senior PM Lead for Microsoft Azure Functions. I help build cloud stuff, and love serverless. Thoughts shared are my own.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade