-
-
Couldn't load subscription status.
- Fork 237
Description
I used version 1.2.8 today to do dynamic sorting in my project. Some of my sortable properties are actually foreign keys- and since I don't want to sort by keys, but by a property on the linked object, I dynamically adapt the query - include the subtable in the IQueryable, and rewrite the property I sort by (instead of NavigationPropertyFK, I'm using NavigationProperty.Name so in the end I'm sorting by the name property of the navigation property).
All this works fine as long as my navigation property is non nullable. If it is nullable, I'm using the np operator on the property I'm odering by, and once the IQueryable gets evaluated, I get this
The LINQ expression 'DbSet<CiscoProfile> .Cast() .Join( outer: DbSet<Cluster>, inner: e => EF.Property<Nullable<Guid>>(e, "ClusterId"), outerKeySelector: c0 => EF.Property<Nullable<Guid>>(c0, "Id"), innerKeySelector: (o, i) => new TransparentIdentifier<CiscoProfile, Cluster>( Outer = o, Inner = i )) .OrderBy(e => e.Outer != null && e.Inner != null ? e.Inner.Name : null)' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
my IQueryable is from EFCore 3.1 (I first created a test project with POCO classes where it worked fine).
my parameter for SortBy is
"np(Cluster.Name)"
The tip to use AsEnumerable would be killer here - it bombs out on a count (I'm doing paging and returning just the page and the count of all items - so I absolutely want to avoid AsNumerable or I'm undoing the whole performance gain I get from paging). As I said, if it's a non nullable navigation property, it works (there I'm using just "Cluster.Name"), but I'd like this to work on both nullable and non nullable navigation properties.