Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
https://msdnshared.blob.core.windows.net/media/2016/08/7827.NinjaAwardTinyBronze.pngBronze Award Winner
Introduction
Using MVC, Entity Framework, ASP.NET5 Scaffolding, and Azure SQLServer you can create a web application that stores your information on an SQL Azure database. This demo shows you how to create a web application with MVC and Entity Framework 7, that communicate with a SQL Azure database.
STEP 1 - Create Azure Account
You need to get a Windows Azure account. Everyone can open a Windows Azure account for free.
Check the link below for more information.
http://www.windowsazure.com/en-us/pricing/free-trial/
https://code.msdn.microsoft.com/site/view/file/146758/1/1.png
STEP 2 - Create SQL Database on Windows Azure
After you get access to an Azure Account, we need to create a SQL Database to store your data.
So for that we need to select the option New on the left bottom of our web page and then select the option Data + Storage -> SQL Database-> Set the name and provide the configurations you need.
On this case our SQL Database will have the name "SQLDemoAzure".
https://code.msdn.microsoft.com/site/view/file/146759/1/2.png
After created the SQL Database, we need to get the connection string that will be used on Web Application to access the Azure SQL Database.
For that, select the database created and on the main window, on the right side, we have an option called "Show Connection String".
When we select that option, a new tab will appear, like the following image, with the connection string formatted to different providers.
https://code.msdn.microsoft.com/site/view/file/146760/1/3.png
STEP 3 - Create ASP.NET 5 Web Application
- Open Visual Studio 2015 and create a new project of type ASP.NET 5 Web Application.
- For this project we created a solution called Demo.
https://code.msdn.microsoft.com/site/view/file/146203/1/1.png
- Press OK and a new screen will appear with several options of template to use on our project.
- Select the option MVC.
https://code.msdn.microsoft.com/site/view/file/146204/1/2.png
After selection of our template, your first web application using ASP.NET 5 is created.
https://code.msdn.microsoft.com/site/view/file/146206/1/3.png
STEP 4 - Create Data Model
After we have our web application created, we need to create our data model.
For that, select the option Add New Item on solution and choose the option Class. Create the class like the one on the image above.
https://code.msdn.microsoft.com/site/view/file/146208/1/4.png
STEP 5 - Scaffolding
This could be made easily using the Scaffolding functionality.
On the solution on the top of controller folder, select the option Add New Scaffold Item.
On the new screen, select the option MVC6 Controller with views using Entity Framework.
https://code.msdn.microsoft.com/site/view/file/146209/1/5.png
Select the name of the controller, class model and data context class.
https://code.msdn.microsoft.com/site/view/file/146210/1/6.png
The new controllers and views associated was created with success.
https://code.msdn.microsoft.com/site/view/file/146211/1/7.png
STEP 6 - Change Connection String
For that just copy your database connection string as explained in Step 1 and pasd into appsettings.json file.
https://code.msdn.microsoft.com/site/view/file/146761/1/10.png
STEP 7 - Change Menu Layout
To test the two tables, we can add two new entries on the web application menu.
https://code.msdn.microsoft.com/site/view/file/146213/1/8.png
STEP 8 - Run Application
Press the F5 button to run the web application.
The new entities appear on the menu.
https://code.msdn.microsoft.com/site/view/file/146216/1/9.png
Press the option car to see our entity in action
https://code.msdn.microsoft.com/site/view/file/146762/1/13.png
Checking the database, you can see the table corresponding to the entity created and the data inserted.
https://code.msdn.microsoft.com/site/view/file/146763/1/14.png