I have a collection of entities.
One of the properties is an enumeration.
How can I sort the collection alphabetically by its enum name instead of value?
In LINQ it would look like this:
var a = collection.OrderBy(x => Enum.GetName(x.OrderType.GetType(), x.OrderType)).ToList();
I can't seem to translate this to Dynamic Linq.
I tried to put it directly, but it throws an Exception:
collection.OrderBy("x => Enum.GetName(x.OrderType.GetType(), x.OrderType) ascending")
For .net framework (not core), see this answer: Call function in dynamic linq which explains that only certain types are available in dynamic linq expressions. Full list of types available in source code
For the dotnet core answer, see the documentation at https://dynamic-linq.net/advanced-configuration . You need to create a custom type provider, than create a parser configuration and use that in your query.
Example below.
output