IQueryable.OrderBy is not working with IComparer in EF Core

Viewed 412

We have a signature of a method in a IQueryable interface:

public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer);

I am trying to implement this call like

var result = await DbSet.OrderBy(e => e.Type, new EntityTypeComparer()).ToListAsync();

But it throws the exception "The LINQ expression could not be translated".

Can you share any working examples of IComparer with EF Core? Or how I can implement custom sorting logic for int property in EF Core?

P.S. Microsoft docs says that IComparer is not supported. But what do we need IQueryable.OrderBy with IComparer parameter for?

1 Answers
Related