Unplanned
Last Updated: 06 Aug 2024 06:52 by ADMIN
Ben
Created on: 15 May 2024 08:33
Category: UI for Blazor
Type: Bug Report
6
Ensure EF Core & EF provide the same behavior when using the DataSource package
The IsEntityFrameworkProvider method in the DataSource package returns false when the provider is Entity Framework Core. 
2 comments
ADMIN
Dimo
Posted on: 06 Aug 2024 06:52

Thanks for the housekeeping, Ben, I appreciate it!

Ben
Posted on: 30 Jul 2024 15:05

Adding details from my original private support ticket.

 

Our application is logging many warnings of the form:

The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.

I have tracked this down to queries where we are using .ToDataSourceResult() (e.g. for server-paged Telerik data grids).

I note that the expected behaviour appears to be that this will sort by the first sortable member if no sort descriptors are provided. However, this is only applied when the LINQ provider is Entity Framework. We are using EF Core - I would have expected that the behaviour would be consistent here?

The Telerik DataSource code checks the provider name like so:

    public static bool IsEntityFrameworkProvider(this IQueryProvider provider)
    {
        string fullName = provider.GetType().FullName;
        if (!(fullName == "System.Data.Objects.ELinq.ObjectQueryProvider") && !(fullName == "System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider") && !fullName.StartsWith("LinqKit.ExpandableQueryProvider") && !fullName.StartsWith("Microsoft.Data.Entity.Query.EntityQueryProvider"))
        {
            return fullName.StartsWith("System.Data.Entity.Internal.Linq");
        }

        return true;
    }

However, in EF Core the provider name is:

"Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider"

And therefore Telerik's current code does not detect EF Core correctly.