Entity Framework Data
- 3 minutes to read
The Data Source Configuration Wizard allows you to bind the PivotGridControl to a SQL database using Entity Framework at design time. Follow the steps below to accomplish this task.
Open the form with the PivotGridControl in Visual Studio Designer. Click the Data Source Wizard button located on the PivotGridControl design surface or use the related command in the control’s smart tag.
In the invoked Data Source Configuration Wizard, select Entity Framework…
… and click the New Data Source button located in the Data Sources area.
The following message appears:
Click OK.
Make sure that the ADO.NET Entity Data Model item is selected in the invoked dialog. Then, specify the name (in this example, NorthWindModel) and click Add.
The following image gallery shows the Entity Data Model Wizard in three steps required to create the Data Model.
When you click Finish at the last Entity Data Model Wizard screen, the following warning appears:
Click OK to run the Entity Framework template that creates a data model.
The created model looks as follows:
Important
After you create a data model, rebuild the solution.
After creating a data model, click the Data Source Wizard button again.
In the invoked Data Source Configuration Wizard, select the created data source.
Click Next.
On the next page, select the binding method.
- Direct Binding to Data Source - allows you to bind the PivotGridControl to an Entity Framework data source directly.
- Binding via the BindingSource Component - allows you to bind the PivotGridControl to a data source with the BindingSource component that simplifies design-time data binding. Refer to the BindingSource Component Specifics article for more information.
- Server Side Data Processing - allows you to bind the PivotGridControl to large data sources. Refer to the Database Server Mode article for more information.
Select Direct Binding to Data Source and click Next.
On the final page, specify the data source table..
.. and click Finish.
The Data Source Configuration Wizard generates the following code:
using System.Data.Entity; using System.Windows.Forms; // ... public Form1() { InitializeComponent(); // This line of code is generated by Data Source Configuration Wizard // Instantiate a new DBContext LinqToSqlServerModeExample.NWEntities1 dbContext = new LinqToSqlServerModeExample.NWEntities1(); // Call the Load method to get the data for the given DbSet from the database. dbContext.Invoices.Load(); // This line of code is generated by Data Source Configuration Wizard pivotGridControl1.DataSource = dbContext.Invoices.Local.ToBindingList(); }