✅ Replacing Linq.Dynamic
I am trying to replace the System.Linq.Dynamic.Core package with regular LINQ in my ASP.NET Core application. I have a method that applies filtering, sorting, and pagination to a queryable collection of entities, using the System.Linq.Dynamic.Core package. Here is the code from my method:
I'm tried something like this
But this obviously doesn't work.
Is there a way to sort a queryable collection of entities based on a property, using regular LINQ and Entity Framework Core? Downloading all entities to the memory and sorting them in the asp.net core app is not an option.
4 Replies
collection.OrderBy(thing => thing.Property)
I wish it could be so easy. I'm dealing with a generic method.
So?
Whatever you're sorting, you sort it by something
So pull that property out to an interface, for example
Add a generic constraint to that interface
And order by that property
I know. But the problem is that this method is entirely generic.
The constraints it has is class and new(). That's all that I know about the type.
But anyway, I decided to make this method in another way. This question is not relevant anymore.