Introduction
In this article, we will see the following things -
- Prerequisites
- Implementation – Creating simple Empty MVC Web application
- Implementation – Connecting current application with Azure SQL using Entity Framework.
Prerequisites
- Some basic knowledge of Azure, like how to create in SQL Azure.
- Read this article for the basics of SQL Azure.
Implementation – Creating a simple empty MVC Web application
- Open Visual Studio that is preinstalled in your system.
- Go to File - New - Project and select Web Template - ASP.NET Web Application.
- Then, select empty MVC Template, as shown below.
- Now, create Home Controller in the Controllers folder.
- Right click on Controllers folder and click on Add - Controller.
- Add an empty Controller.
- Now, create an empty View.
- For that, right click on the index method and Add View.
Implementation – Connecting current application with Azure SQL using Entity Framework.
- Now, create a SQL database in Azure.
- To create a SQL database in Azure, follow this article.
- Connect it with local SQL Server using server name as the connection string and create a Employee table in it, as shown below.
- Now, configure the database in your application using Entity Framework.
- Right click on Project and install Entity Framework from NuGet packages by choosing the option “Manage packages”.
- Now, add the .edmx file as DB first approach and connect with SQL Azure entities, as shown below.
- Select EF designer from Database, as shown below.
- Then, choose the server name from SQL Azure DB Properties on the portal and create SQL Server connection using the credentials; choose DB from there and click on OK.
- Now, choose the table from the menu and click "Finish".
- Now, go to Controller and add some lines of code to insert into Employee table.
- Now, run the application and check employee table data from the SQL Server Object Explorer.
This is how we can use SQL Azure with Entity Framework.
Happy Learning.