8.11.4. Using EDM to create Entity Framework based applications
Now that a Microsoft Entity Data Model has been created for the Northwind database, Entity Framework applications can be created to make use of it.
Visual Studio Windows DataGrid Form Application
This section details the steps required to create a simple Visual Studio 2008 Windows Form application, with associated DataGridView control for displaying data in selected tables from the target database.
-
Launch the Visual Studio 2008 SP1 IDE.
Figure 8.573. Visual Studio 2008 SP1 IDE
-
Create a
Web Application
project by going to the
File
menu in Visual Studio and choosing
New Project
.
Figure 8.574. Web Application
-
When the New Project window appears, choose either
Visual Basic
or
Visual C#
as your programming language.
-
Within the language category, click on
Windows
and select
Windows Form Application
from the right-hand panel.
-
Choose a name for the project, for example
VirtWindowsFormApplication
, and click
OK
.
Figure 8.575. Web Application
-
In the
Toolbox
, expand
Data Controls
, and drag the
DataGridView
control onto the form.
Figure 8.576. Toolbox
-
Click on the little
arrow
in the top right of the
DataGridView
control. This loads the
DataGridView Task
menu.
Figure 8.577. DataGridView Task
-
Click on the
Choose Data Source
list box.
Figure 8.578. Choose Data Source
-
Click on the
Add Project Data Source
link to connect to a data source.
Figure 8.579. Add Project Data Source
-
In the
Data Source Configuration Wizard
dialog
Choose Data Source Type
page select the
Database
data source type and click
Next
.
Figure 8.580. Data Source Type
-
In the
Data Source Configuration Wizard
dialog
Choose your Data Connection
page, select the
New Connection
button
Figure 8.581. Data Source Configuration Wizard
-
In the
Choose Data Source
dialog, select the OpenLink
Virtuoso Data Source
from the list and click
Continue
.
Figure 8.582. Data Source
-
In the
Add Connection
dialog, specify the
hostname, portno, username and password
for the target Virtuoso Server and check the Save Password check box.
Figure 8.583. Connection Properties
-
Select the
Select Database From List
radio button and choose the
NWIND
database from the drop down list.
Figure 8.584. Add connection
-
Press the
Test Connection
dialog to verify that the database is accessible.
Figure 8.585. Test Connection
-
Leave the default connect string
NWINDConnectionString
and click
Next
Figure 8.586. NWINDConnectionString
-
From the list of available tables returned for the NWIND database, select the
JOBS
table to be associated with the
DataGridView
control.
Figure 8.587. Northwind database
-
The columns names of the select table will be displayed in the DataGridView.
Figure 8.588. DataGridView
-
Resize the Form and DataGridView to allow all columns to be visible, if possible.
Figure 8.589. Resize the Form and DataGridView
-
To test the application, simply hit
Ctrl+F5
within Visual Studio or select
Start Debugging
from the
Debug
menu.
Figure 8.590. Start Debugging
-
The data from the
Products
table will be displayed in the
DataGrid
.
Figure 8.591. DataGrid
The task is now complete.