Last post Jul 05, 2015 05:22 PM by mostafasydney
Jul 03, 2015 01:24 PM|desikankannan|LINK
i have table tbl_broker i would like to connect the sql database using azure mvc , please guide me to connect db with dbcontext method
Jul 05, 2015 05:22 PM|mostafasydney|LINK
If I am not wrong you are using Azure SQL database and would like to access the database using Entity Framework in you MVC application, right?
Well, you can follow both Database-First or Model-First approach with Entity Frame work to work with the database.
If you use Database-First i.e. you have an existing database and you would like to use the tables from the database as models in your MVC. To add the Database to your MVC project, Add new new item to your project and select
Data from the template and you will get the following screen:
Select ADO.NET Entity Data Model and you will see
After selecting the option from the wizard it will ask for the Database connection string and if the connection is ok then it will generate a metadata connection string in your web.config file which you will be using for database access.
In the Model-First (Code-First) you need to add the connection string to you DbContext class and add the models to the class. After having done these, you need to migrate the models to the database if you code successfully builds.
There are 3 commands you need to issue from Power Shell Console
These will create the database in your server and ready to use.
Please see this post how to connect to a database using Code-First approach:
Hope this will help