You don't have to create a connection string. If you don't create one, the Entity Framework will automatically create a SQL Server Express database for you. In this tutorial, however, you'll work with SQL Server Compact, so you need to create a connection string to specify that.
Open the project Web.config file and add a new connection string to the connectionStrings collection, as shown in the following example. (Make sure you update the Web.config file in the root project folder. There's also a Web.config file is in the Views subfolder that you don't need to update. )
<add name="SchoolContext" connectionString="DataSource=|DataDirectory|School.sdf" providerName="System.Data.SqlServerCe.4.0"/>
By default, the Entity Framework looks for a connection string named the same as the object context class. The connection string you've added specifies a SQL Server Compact database named School.sdf located in the App_Data folder.
Getting Started with Entity Framework Code First
Introduction to POCO classes in Entity Framework
Create First MVC application in Visual Studio 2010
Creating the Entity Framework Data Model in Visual Studio
Create classes for each entity using Entity Framework
Create the Database Context using Entity Framework
Setting the Connection String in MVC Asp.Net Application
Creating a Controller and Views in MVC application
0 comments:
Post a Comment