I’ve just started using Entity Framework, and I’ve found that it really helps speed up development time when dealing with queries where performance isn’t a huge issue.
I added to an existing project which needed to keep the EF classes isolated in the data layer. This made it difficult to pass in a sort order without having a massive switch statement to deal with each of the options.
I solved this by building an OrderBy extension method that takes a string, and builds the sort expression using reflection. This means you can sort without having to know the actual type of what you’re ordering by.
Here’s the Gist:
5 Responses to “ “OrderBy a string in Entity Framework”
Great job, thanks for the help. Will pass this on.
About Me
I'm primarily a .NET developer, an architect and a rationalist. I dabble in F#, node.js and other tools and techniques that might make me a better developer and I'd like to share what I learn.
This is good stuff. Is it possible with this to do an order by that is case insensitive?
Thanks
so good
this is great code
Thank you.
You made my day bro! I have been implementing a entity-independent system and this works like a charm!
Great job, thanks for the help. Will pass this on.