Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF.Property called with wrong property name when using System.Linq.Dynamic.Core OrderBy on multiple columns #19838

Closed
appimpact opened this issue Feb 8, 2020 · 4 comments

Comments

@appimpact
Copy link

We have been using System.Linq.Dynamic.Core for quite some time to generate various dynamic queries. Since upgrade to EF Core 3.0.0/3.1.1, all application queries using .OrderBy("column1,column2 ASC") have stopped to work, with the following exception being thrown:

"EF.Property called with wrong property name".

We have tried to revert back to .NET Core 2.2 / EF Core 2.2.6, and code works as expected.

Steps to reproduce

An example of code that generates this error can be found on this GitHub repository:
https://github.com/App-Impact-Labs/ISSUE-EfCorePropertyCalledWithWrongPropertyName

The code above will create database, seed basic data and generate an error that can be further inspected.

Further technical details

EF Core version: 3.0.0 - 3.1.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0 - 3.1
Operating system: Windows 10 x64, Windows Server 2016 x64
IDE: e.g. Visual Studio 2019 16.3

@smitpatel
Copy link
Contributor

Duplicate of #18904

@smitpatel smitpatel marked this as a duplicate of #18904 Feb 8, 2020
@appimpact
Copy link
Author

appimpact commented Feb 8, 2020

Hi @smitpatel ,

The workaround you've provided in #18904 is not useful to us as we are using System.Linq.Dynamic.Core, so we cannot really expand the query the way you have specified.

Can you provide workaround for this particular issue, or at least ETA on when appropriate fix can be expected?

@smitpatel
Copy link
Contributor

The fix will be released in EF Core 5.0 which is tentative going RTM this November.
Work-around: (did not test with dynamic LINQ)

                var entities = dbContext.Entities
                    .Join(dbContext.Resources,
                    e => e.NameId,
                    i => i.Id,
                    (o, i) => new { Entity = o, Name = i })
                    .Join(dbContext.Resources,
                    e => e.Entity.DescriptionId,
                    i => i.Id,
                    (o, i) => new { Entity = o.Entity, Name = o.Name, Description = i })
                    .Select(e => new EntityDto
                    {
                        NameFormatted = e.Name.Translations
                         .Where(x => x.LocaleId == localeId)
                         .Select(x => x.Value)
                         .FirstOrDefault(),
                        DescriptionFormatted = e.Description.Translations
                         .Where(x => x.LocaleId == localeId)
                         .Select(x => x.Value)
                         .FirstOrDefault()
                    })
                    .OrderBy(e => e.DescriptionFormatted).ThenBy(e => e.NameFormatted)
                    //.OrderBy($"{col} {ord}")
                    .ToList();

@appimpact
Copy link
Author

@smitpatel

Ok, it seems it works well. We will do more testing and let you know if we notice anything unusual.

Thank you!

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants