KB Article KA18959
Visible to All Users

Entity Framework 6+ and Entity Framework Core with Server and Instant Feedback Modes

For v19.1+

EntityServerModeSource and EntityInstantFeedbackSource automatically detect the Entity Framework version and use appropriate EntityFunctions and SqlFunctions.

To register a custom query provider, use the DevExpress.Data.Linq.CriteriaToEFExpressionConverter.RegisterCustomQueryProviderType method:

C#
void Application_Start() { using(var context = new EfContext()) { var qEf = (IQueryable)context.BuildingObjects; var qDecompiled = (IQueryable)qEf.Decompile(); DevExpress.Data.Linq.CriteriaToEFExpressionConverter.RegisterCustomQueryProviderType(qDecompiled.Provider.GetType(), qEf.Provider.GetType()); } }

For v14.1 - v19.1

Some breaking changes introduced in Entity Framework 6.0 caused compatibility issues with Entity Framework Server Mode collections (EntityServerModeSource, EntityInstantFeedbackSource).

Known issues

  • Filtering via the Auto Filter Row against numeric columns is not supported.
  • Searching via the Find 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 operation is not supported.

Workaround

We introduced a new feature that allows you to specify classes which will be used by our library to get methods that call functions in the database.

In Entity Framework 6.0 these classes are:
System.Data.Entity.Core.Objects.EntityFunctions
System.Data.Entity.SqlServer.SqlFunctions

C#
DevExpress.Data.Linq.CriteriaToEFExpressionConverter.EntityFunctionsType = typeof(System.Data.Entity.Core.Objects.EntityFunctions); DevExpress.Data.Linq.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.

C#
DevExpress.Data.Linq.CriteriaToEFExpressionConverter.EntityFunctionsType = typeof(System.Data.Entity.DbFunctions); DevExpress.Data.Linq.CriteriaToEFExpressionConverter.SqlFunctionsType = typeof(System.Data.Entity.SqlServer.SqlFunctions);

In Entity Framework Core 2.1+ only the Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions class should be used.

C#
DevExpress.Data.Linq.CriteriaToEFExpressionConverter.EntityFunctionsType = typeof(Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions);

If you experience issues listed in the description to this article, execute the code above in your application's entry point. This will resolve problems caused by this limitation.

Note: The information above is applicable only for Server Mode data sources, because they configure the CriteriaToEFExpressionConverter instance internally. If you are creating the CriteriaToEFExpressionConverter instance manually (e.g., for the CriteriaToQueryableExtender.AppendWhere method), you also need to pass the query type to its constructor:

C#
var result = CriteriaToQueryableExtender.AppendWhere(queryable, new CriteriaToEFExpressionConverter(queryable.Provider.GetType()), criteria);
Show previous comments (7)
DevExpress Support Team 10 years ago

    Hello Sam,

    This ticket is closed, as the solution was provided. I see that you submitted a separate ticket describing the issue you are experiencing: GridView - DateRangePicker doesn't work correctly when the BindToEF method is used. From what I gather, my colleagues helped you. Please let me know if you need any further assistance.

      Two clarifications:

      One

      Code
      For v19.1+ EntityServerModeSource and EntityInstantFeedbackSource automatically detect the Entity Framework version and use appropriate EntityFunctions and SqlFunctions.

      So just to be sure, from 19.1 onwards, we dont have to write these two lines of code, right?

      C#
      CriteriaToEFExpressionConverter.EntityFunctionsType = typeof(DbFunctions); CriteriaToEFExpressionConverter.SqlFunctionsType = typeof(SqlFunctions);

      Two

      Code
      If you are creating the CriteriaToEFExpressionConverter instance manually (e.g., for the CriteriaToQueryableExtender.AppendWhere method), you also need to pass the query type to its constructor: var result = CriteriaToQueryableExtender.AppendWhere(queryable, new CriteriaToEFExpressionConverter(queryable.GetType()), criteria);

      The constructor parameter of CriteriaToEFExpressionConverter is Type queryProviderType. So I wonder if it should be queryable.GetType() or queryable.Provider.GetType(). I just checked the source code and looks like it makes no difference, but I wanted a confirmation from you.

      DevExpress Support Team 4 years ago

        Hello Nawfal,

        I created a separate ticket on your behalf: T1045022: KA18959 clarifications. We placed it in our processing queue and will process it shortly.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.