Image for post
Image for post
Original photo by Jan Antonin Kolar on Unsplash

Serverless relational code first database apps in Azure

How to built a cloud native app with Azure Functions to create, design and connect to a Azure Database for PostgreSQL using .Net Core and EntityFramework Core

Philipp Bauknecht
Nov 29, 2020 · 5 min read

Why?

Prerequisites

Create a new PostgreSQL database server in the Azure Portal

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Create a new database with Azure Data Studio

Image for post
Image for post
Image for post
Image for post
CREATE DATABASE ServerlessDemo
Image for post
Image for post

Let’s write some code!

Step 1: Code first model

Step 2: Database Context

Step 3: Service

Step 4: Configure dependency injection

Step 5: Enable design-time context creation and adding a migration

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

Step 6: Http Functions

Step 7: Test with Postman

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Summary

medialesson

We help our customers design, architect, develop and…

Philipp Bauknecht

Written by

CEO @ medialesson. Microsoft Regional Director & MVP Windows Development. Father of identical twins. Passionate about great User Interfaces, NYC & Steaks

medialesson

We help our customers design, architect, develop and operate modern, intelligent, beautiful and usable apps on any platform powered by the Cloud, IoT and AI.

Philipp Bauknecht

Written by

CEO @ medialesson. Microsoft Regional Director & MVP Windows Development. Father of identical twins. Passionate about great User Interfaces, NYC & Steaks

medialesson

We help our customers design, architect, develop and operate modern, intelligent, beautiful and usable apps on any platform powered by the Cloud, IoT and AI.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store