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
Step 2
Step 3
Step 4
Step 5
Instant Feedback Mode
- Create a new EntityInstantFeedbackDataSource data source instance.
- Handle the data source’s EntityInstantFeedbackDataSource.GetQueryable event. In the event handler, specify the newly created queryable source for the data source.
- Handle the EntityInstantFeedbackDataSource.DismissQueryable event. In the event handler, dispose of the unnecessary queryable sources.
- 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
- Create a new instance of the EntityServerModeSource class.
- Specify the type of objects retrieved from a data source, the key expression and queryable source.
- 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
- Entity Framework 4.0+: The maximum allowed number of total or group summaries is 14.
- 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.
- 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);