The next step is to create an entity modal using the new
Entity Framework 4. Once you have a modal you can then add EntityDataSource
controls to you application that can dynamically query your database.
1.
Right click on the web site in the Solution Explorer and select Add New
Item… from the pop-up menu.
2.
Select ADO.NET Entity Data Model from the list of templates. Change the
file name to AdventureWorksModel.edmx and click the Add button. You'll get a
message asking if you want to create an App_Code folder.
3.
Click Yes. This will display the Entity Data Model Wizard.
4.
Choose Generate From Database and click the Next button.
5.
The next screen asks you to choose a data connection. The drop down
list will display any connections you have already setup in the Server
Explorer. If you haven't already created a connection to the AdventureWorks
database then click the New Connection button.
6.
This displays the Connection Properties form. Enter your server name,
authentication information, and select the AdventureWorks database from the list
of available databases.
7.
Click the Test Connection button to make sure you have entered the right
information. If you get an error fix the settings and try again.
8.
Once testing the connection is successful click the OK button.
9.
The AdventureWorks connection should appear in the list of connections
and be selected.
10. Make
sure the "Save entity connection settings in Web.Config as" checkbox
is checked.
11. Click
the Next button.
12. The
next form in the wizard allows you to select which tables, views, or stored
procedures you want to add to the model. We're only going to be editing the
Contact table so expand the Tables node and check the box next to the Contact
table.
13. Click
the Finish button. Visual Studio will add the AdventureWorks entity data model
to your web site.