Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

ASP.NET Zero Upgrade from 6.2.0 to 13.1.1 Version: Entity Framework Core Linq to SQL Exception #12075


User avatar
0
razkhan78 created

Hi Team,

We are upgrading our existing application (Asp.net Core MVC + Jquery with framework .net2.1 and version 6.2.1.) to .net 8 and version 13.1.1. following documentation (Version-Updating).

We have successfully build and run project after resolving conflicts. Now problem is that ABP latest version 9.2.2 is using EF Core 8 and our Linq queries which was working fine before upgrade (EF Core 2.1.4). Now below exception is occuring due to Entity Framework Core 3.x and later versions introduced stricter rules for translating LINQ queries to SQL.

Database: Azure SQL Database and Compatibility Level is 140

Example of Linq Query:

var recurrenceLst = _activityRepository.GetAllIncluding(x => x.CustomerFk, x => x.ContactFk) .Where(x => x.StatusId != (int)Status.Completed && x.IsRecurring && ((x.RecurrenceType == RecurrenceType.Monthly && (x.RecurrenceMonthDay == DateTime.Today.Day || (x.RecurrenceMonthDay > lastDayOfMonth && DateTime.Today.Day == lastDayOfMonth))) || (x.RecurrenceType == RecurrenceType.Weekly && x.RecurrenceWeekDay == (WeekDay)((int)DateTime.Today.DayOfWeek + 1)))).ToList();

Exception: The LINQ expression 'DbSet<Activity>() .Where(a => __ef_filter__p_0 || (int?)((IMustHaveTenant)a).TenantId == __ef_filter__CurrentTenantId_1) .Where(a => a.StatusId != 2 && a.IsRecurring && (int?)a.RecurrenceType == (int?)Monthly && a.RecurrenceMonthDay == (int?)DateTime.Today.Day || a.RecurrenceMonthDay > __lastDayOfMonth_0 && DateTime.Today.Day == __lastDayOfMonth_1 || (int?)a.RecurrenceType == (int?)Weekly && (int?)a.RecurrenceWeekDay == (int?)(WeekDay)((int)DateTime.Today.DayOfWeek + 1))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Solution Tried: We have thousands of Linq queries in a project and to avoid rewrite query and to load a lot of data in Memory and then filter, we tried to keep previous version of EFCore (2.1.4) and all related packages of EF Core to (2.1.4) But no success, project doesn't run and get another exception in LoadStopDbContextConfigurer file at builder.UseSqlServer(connectionString);

Exception System.TypeLoadException: 'Method 'get_Info' in type 'Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerOptionsExtension' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=2.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'

Please give a solution or suggestion. Right now its not possible to rewrite thousands of Linq Queries according to EF Core 8. What we can do to support current written Linq queries?


5 Answer(s)
  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @razkhan78,

    Could you share your nuget packages(with versions) at *.EntityFrameworkCore project

  • User Avatar
    0
    razkhan78 created

    Here is nuget packages(with versions) at *.EntityFrameworkCore project.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @razkhan78

    You should either stay at EF Core 2.1 and downgrade your ABP packages or you need to use EF Core 8.x and fix your queries. There was a switch to enable client side evaluation but it is not availabe anymore in EF Core I think.

  • User Avatar
    0
    razkhan78 created

    we tried to stay at EF Core 2.1 without downgrade ABP packages (we cannot downgrade ABP packages because we are upgrading) but another exception comes as I have mentioned above in solution tried section and project doesn't run.

    Is there any other solution other than fix queries?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    As far as I know, no. Because EF Core 2.1 and some of .NET Core 8 packages are using some common libraries and probably your app is loading different version of some of the packages and it causes runtime errors.

    In many apps moving from EF Core 2.1 to 3.x developed by AspNet Zero, there shouldn't be many queries to fix. You can give it a try.