Skip to main content
A newer version of this page is available. .

Server Mode with Entity Framework

  • 3 minutes to read

The PivotGridControl automatically operates in server mode if it is bound to the Entity Framework data source. This example demonstrates how to generate model and mapping information, and bind the Pivot Grid control to the data source with the Entity Framework.

Creating Data Classes

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

    Server Mode Entity Add Model

  2. Create a model in the EF Designer based on an existing database. You can choose the model type, a database connection string, the objects to include in the model. The following image gallery shows the Entity Data Model Wizard:

    When you click Finish at the last Entity Data Model Wizard screen, the following warning appears:

    The created model looks as follows:

    entity-data-model-browser

Important

After you create a data model, rebuild the solution.

Binding PivotGridControl to the EntityServerModeSource component

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

    Server Mode Entity Add Component

    Note

    Alternatively, you can create the EntityServerModeSource in code at runtime.

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

    entityServerModeSource = new EntityServerModeSource
    {
        ElementType = typeof(EntityInvoice),
        KeyExpression = "OrderId"
    };
    
  3. Specify the queryable source with the EntityServerModeSource.QueryableSource property.

    NWEntities context = new NWEntities();
    entityServerModeSource.QueryableSource = context.EntityInvoices;
    
  4. Bind the Pivot Grid control to the EntityServerModeSource component.

    pivotGridControl1.DataSource = entityServerModeSource;
    

    The resulting code looks as follows:

    using DevExpress.Data.Linq;
    using DevExpress.XtraEditors;
    using System;
    
    namespace EntityFrameworkServerModeExample
    {
        public partial class Form1 : XtraForm
        {
            EntityServerModeSource entityServerModeSource;
            public Form1()
            {
                InitializeComponent();
                entityServerModeSource = new EntityServerModeSource
                {
                    ElementType = typeof(EntityInvoice),
                    KeyExpression = "OrderId"
                };
                NWEntities context = new NWEntities(
                //Enable query logging.
                context.Database.Log = Console.Write;
                entityServerModeSource.QueryableSource = context.EntityInvoices;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                    pivotGridControl1.DataSource = entityServerModeSource;
            }
        }
    }
    
  5. Run the project. The PivotGridControl works in server mode. You can see the generated SQL statements in the Visual Studio Output window.

Note

The complete sample project PivotGridControl and Entity Framework - a Server Mode Example is available in the DevExpress Examples repository..

See Also