A newer version of this page is available. Switch to the current version.

Binding to a Data Source Using Entity Framework

  • 2 minutes to read

The PivotGridControl automatically operates in server mode if it is bound to appropriate supported data source. This example demonstrates how to generate model and mapping information, and bind the pivot grid to the data source using the Entity Framework.

Creating Data Classes

  • Add ADO.NET Entity Data Model to the project.

    Server Mode Entity Add Model

  • Create a model in the EF Designer based on an existing database. You can choose the database connection, settings for the model, and database objects to include in the model. The classes your application will interact with are generated from the model.

    You can specify the model by dragging database tables and views from Server Explorer to the model.

    Server Mode Entity EDMX Diagram

    Save your changes and rebuild the solution.

Binding a Pivot Grid Control to the EntityServerModeSource component

  • Drag the EntityServerModeSource component and drop it onto the Form.

    Server Mode Entity Add Component

  • Specify the type of objects retrieved from a data source using the EntityServerModeSource.ElementType and EntityServerModeSource.KeyExpression properties.

    entityServerModeSource1.ElementType = typeof(EntityServerModeApp.SalesPerson);
    entityServerModeSource1.KeyExpression = "OrderID";
  • Specify the queryable source with the EntityServerModeSource.QueryableSource property. This property must be set in code.

    public Form1() {
        entityServerModeSource1.QueryableSource = new EntityServerModeApp.NWindEntities().SalesPersons;
  • Bind the Pivot Grid control to the EntityServerModeSource component.

    pivotGridControl1.DataSource = entityServerModeSource1;

To learn how to bind the PivotGridControl to data using the Data Source Configuration Wizard, see the Entity Framework Data tutorial.

See Also