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

Entity Framework 4.0+ Instant Feedback and Server Mode

  • 3 minutes to read

This document shows how to generate model and mapping information, create queries that access data, and enable Server Mode to bind the query results to the GridControl.

Create a Storage Model and Mapping Information

Add the ADO.NET Entity Data Model item template, and configure it using the Entity Data Model Wizard.

  • Step 1

    ef4ServerMode_AddEFitem

  • Step 2

    ef4ServerMode_Wizard1

  • Step 3

    ef4ServerMode_Wizard2

  • Step 4

    ef4ServerMode_Wizard3

  • Step 5

    ef4ServerMode_SaveModel

Instant Feedback Mode

  1. Create a new EntityInstantFeedbackDataSource data source instance.
  2. Handle the data source’s EntityInstantFeedbackDataSource.GetQueryable event. In the event handler, specify the newly created queryable source for the data source.
  3. Handle the EntityInstantFeedbackDataSource.DismissQueryable event. In the event handler, dispose of the unnecessary queryable sources.
  4. Bind the grid’s DataControlBase.ItemsSource property to the data source.
<dxg:GridControl Name="grid" AutoGenerateColumns="AddNew"/>
using DevExpress.Data.Linq;
using System.Windows;

namespace EFInstFeedback {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            var efDataSource = new EntityInstantFeedbackSource();
            efDataSource.KeyExpression = nameof(Order.OrderID);
            efDataSource.GetQueryable += EfDataSource_GetQueryable;
            efDataSource.DismissQueryable += EfDataSource_DismissQueryable;
            grid.ItemsSource = efDataSource;
        }
        private void EfDataSource_GetQueryable(object sender, GetQueryableEventArgs e) {
            NorthwindEntities objectContext = new NorthwindEntities();
            e.QueryableSource = objectContext.Orders;
            e.Tag = objectContext;
        }
        private void EfDataSource_DismissQueryable(object sender, GetQueryableEventArgs e) {
            ((NorthwindEntities)e.Tag).Dispose();
        }
    }
}

Server Mode

  1. Create a new instance of the EntityServerModeSource class.
  2. Specify the type of objects retrieved from a data source, the key expression and queryable source.
  3. Bind the GridControl to the EntityServerModeSource:
<dxg:GridControl Name="grid" AutoPopulateColumns="True"/>
using DevExpress.Data.Linq;
using System.Windows;

namespace EFServMode {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            grid.ItemsSource = new EntityServerModeSource {
                KeyExpression = nameof(Order.OrderID),
                QueryableSource = new NorthwindEntities().Orders
            };
        }
    }
}

Entity Framework Server Mode Limitations

Compatibility Issues with Entity Framework 6.0 and Entity Framework Server Mode Collections.

Breaking changes introduced in Entity Framework 6.0 caused compatibility issues with Entity Framework Server Mode collections (EntityServerModeDataSource, EntityInstantFeedbackDataSource). Below is the list of limitations.

Limitations
  • Filtering via the Automatic Filter Row against numeric columns is not supported.
  • Searching via the Search Panel against numeric columns is not supported.
  • Incremental searching against numeric columns is not supported.
  • The following column group intervals are not supported:

    • Date
    • DateMonth
    • DateRange
    • DateYear
    • Default (for DateTime columns)
  • A numeric column as display member of the look-up editor is not supported.
  • The following function operators are not supported in filters and unbound columns.

    • ToStr (if the parameter is an operand property referencing a numeric column)
    • AddDays
    • AddHours
    • AddMilliSeconds
    • AddMinutes
    • AddMonths
    • AddSeconds
    • AddYears
    • DateDiffDay
    • DateDiffHour
    • DateDiffMilliSecond
    • DateDiffMinute
    • DateDiffMonth
    • DateDiffSecond
    • DateDiffYear
    • GetDate
  • The Like binary operator is not supported.

To resolve problems with these limitations, execute the following code in your application’s entry point.

EF 6.0 only:

CriteriaToEFExpressionConverter.EntityFunctionsType = typeof(System.Data.Entity.Core.Objects.EntityFunctions);
CriteriaToEFExpressionConverter.SqlFunctionsType = typeof(System.Data.Entity.SqlServer.SqlFunctions);

In Entity Framework 6.1, the System.Data.Entity.Core.Objects.EntityFunctions is obsolete, and the System.Data.Entity.DbFunctions class should be used.

CriteriaToEFExpressionConverter.EntityFunctionsType = typeof(System.Data.Entity.DbFunctions);
CriteriaToEFExpressionConverter.SqlFunctionsType = typeof(System.Data.Entity.SqlServer.SqlFunctions);
See Also