I am trying to dynamically set an order by in Linq with the following code:
Func<TransactionResult, Object> orderByFunc = null;
var sortKey = query.SortOption.Split(":")[0];
var sortDirection = query.SortOption.Split(":")[1];
if (sortKey == "Date")
orderByFunc = item => item.Created;
else if (sortKey == "PatientName")
orderByFunc = item => item.Customer.FirstName;
else if (sortKey == "Status")
orderByFunc = item => item.Status;
else if (sortKey == "Source")
orderByFunc = item => item.Source;
else if (sortKey == "Amount")
orderByFunc = item => item.Amount;
if (sortDirection== "asc")
{
tQuery = tQuery.OrderBy(orderByFunc).AsQueryable();
}
else
{
tQuery = tQuery.OrderByDescending(orderByFunc).AsQueryable();
}
I'm getting the error : The source 'IQueryable' doesn't implement 'IAsyncEnumerable<########.Application.Transaction.Queries.Transactions.TransactionsDto>'. Only sources that implement 'IAsyncEnumerable' can be used for Entity Framework asynchronous operations.
Any help would be much appreciated, thank you.