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”
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.