You can bind an ObjectQuery to a DataGridView control on a Windows form in a few lines of code. This sample demonstrates how to create the ObjectQuery and assign the ObjectQuery to the DataSource property of a DataGridView control. For more information about this sample, see the Adventure Works Data Binding sample topics in the Entity Framework documentation.
Conceptual schema definition language (CSDL)
Store schema definition language (SSDL)
Mapping specification language (MSL)
This sample uses the following features of the Entity Framework.
Entity Data Model
Query builder methods
Project data sources
Before running this sample, make sure the following software is installed:
Visual Studio 2008 SP1 containing the .NET Framework 3.5
SQL Server 2005 or 2008 Database Engine
AdventureWorks sample database
SQL Server Management Studio (optional)
Use the following procedure to build the sample.
(Optional) If the AdventureWorks sample database is not already present in your SQL Server instance, download and install it from Sample Databases for Microsoft SQL Server 2005 SP2.
Open the AdWksSalesWinDataBind solution file in Visual Studio.
(Optional) If you created the AdventureWorks database in an instance of SQL Server other than the default instance on the local machine, specify the correct SQL Server instance by modifying the Data Source in the AdventureworksEntities connection string in the App.Config file of the AdWksSalesWinDataBind project.
Build the project.
Use the following procedure to run the sample.
Run the application.
Enter a SalesOrderHeaderID value in the Order Number text box. Use a number between 43659 and 75123, and click the Get Sales Order button.
In the Sales Order Details data grid, modify the number in the Quantity column, and press Enter.
Line and order totals are updated by business logic on the client.
Click the Add Detail to Order button.
When the Add SalesOrderDetail dialog appears, click to select a Product from the data grid.
Enter a quantity and optional discount, which must be a value between 0 and 1.
Click Create Order. A new order is created and added to the Sales Order Details data grid.
Use the following procedure to remove the AdventureWorks Data Binding sample.
Delete the project directory and contents.
(Optional) Drop the AdventureWorks database from the instance of SQL Server.