I have an EF core entity ("Target") which I display inside a Radzen DataGrid. On this entity I have an unmapped property called "CountUsed".
When I try to sort it, I get the following exception:
[2021-03-08T22:35:22.300Z] Error: System.InvalidOperationException: The LINQ expression 'DbSet()
.Join(
inner: DbSet<ApplicationUser>(),
outerKeySelector: t => EF.Property<string>(t, "CreatorId"),
innerKeySelector: a => EF.Property<string>(a, "Id"),
resultSelector: (o, i) => new TransparentIdentifier<Target, ApplicationUser>(
Outer = o,
Inner = i
))
.Where(t => t.Inner == __currentUser_0 && t.Outer.DomainId == __domainId_1)
.OrderBy(t => t.Outer.Name)
.OrderBy(t => t.Outer.CountUsed)' could not be translated. Additional information: Translation of member 'CountUsed' on entity type 'Target' failed. This commonly occurs when the specified member is unmapped. 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'.
I fetch the list of targets, on page load. The error does not occur, when I call .ToList() on the targets list. But I guess I shouldn't do that in a productive environment (as noted in the documentation of the DataGrid), probably for performance reasons?
So I wonder, how can I avoid this error, without using ToList()?