Using OrderBy on property that was resolved using double ternary operator.
Current behaviour
Sample query from DebugView (the query is way bigger but this is the part that causes the problem):
DbSet<AccountingJournal>()
.Select(journal => new OverviewAccountingJournalMappingSource{
Worker = journal.WorkerAccountingId != null ? <>c__DisplayClass1_0.workers
.SingleOrDefault(w => w.AccountingId == journal.WorkerAccountingId) : journal.WorkerEnterpriseId != null ? <>c__DisplayClass1_0.workers
.SingleOrDefault(w => w.EnterpriseId == journal.WorkerEnterpriseId) : null,
)
.Select(dtoOverviewAccountingJournalMappingSource => new OverviewAccountingJournalWebDto{
WorkerSurname = dtoOverviewAccountingJournalMappingSource.Worker.Surname,
}
)
.OrderByDescending($it => $it.WorkerSurname)
.ThenBy($it => $it.Id)
.Skip(TypedLinqParameterContainer<int>.TypedProperty)
.Take(TypedLinqParameterContainer<int>.TypedProperty)
Produces: System.InvalidOperationException: The LINQ expression 'DbSet<AccountingJournal>() .OrderByDescending(a => a.WorkerAccountingId != null ? DbSet<Worker>() .Where(w => w.AccountingId == a.WorkerAccountingId) .SingleOrDefault() : a.WorkerEnterpriseId != null ? DbSet<Worker>() .Where(w0 => w0.EnterpriseId == a.WorkerEnterpriseId) .SingleOrDefault() : null.Surname)' could not be translated
We suspect that it is caused by it being a double ternary operator as this query containing ternary operator works
DbSet<AccountingJournal>()
.Select(journal => new OverviewAccountingJournalMappingSource{
Client = journal.ClientAccountingId != null ? <>c__DisplayClass1_0.clients
.SingleOrDefault(c => c.AccountingId == journal.ClientAccountingId) : null,
}
)
.Select(dtoOverviewAccountingJournalMappingSource => new OverviewAccountingJournalWebDto{
ClientShortcut = dtoOverviewAccountingJournalMappingSource.Client.Shortcut,
}
)
.OrderBy($it => $it.ClientShortcut)
.ThenBy($it => $it.Id)
.Skip(TypedLinqParameterContainer<int>.TypedProperty)
.Take(TypedLinqParameterContainer<int>.TypedProperty)
Provider being used is npgsql.
@cts-tradeit please take the time to create a minimal, runnable code sample (e.g. a console program) - the above is a very partial snippet without a full exception etc.
sorry, i have been busy and forgot about this, will deliver by the end of this week
Closing as no repro was provided.