Web Configuration Connection String setting in ASP.Net MVC 3 using Entity Framework



Description:

In this article I will describe how to set the Web configuration file in ASP.Net MVC 3 using Entity Framework with object class mapping.

Content:

In your ASP.Net MVC 3 applications supposes you are using object class mapping using Entity Framework.

That means you write your classes using relationships and the classes will be converted to a table in the database. For that you have to set your Web .config file connection string setting. Because the connection string results in mapping a class to a table in the database and the data from the table will also come from the database.

Step 1:

First go to the Web config page for the main project like Figure 1:

ASP.NETMVC1.gif

Figure 1:

Step 2:

Then comment the existing connection string code. (The existing code will not work for creating the tables from the mapping classes (POCO) classes).

After that paste the code shown below like figure 2:

<add name="CabDBContext" connectionString="data source=.;Database=Cabdb;Trusted_Connection=true;" providerName="System.Data.SqlClient" />

ASP.NETMVC2.gif

Figure 2:

I have attached a simple sample ASP.Net MVC3 application here so you can refer to that.

Conclusion:

So in this article we have learned how to change the connection string in the web.config file for ASP.Net MVC 3 using Entity Framework.


Similar Articles