Entity Framework Sorting/ Ordering and Dynamic LINQ

One of my coworkers would like me to update my IEnumerable SortBy extension method to support multiple columns. As I was working on it, I stumbled upon a nice StackOverflow question on Dynamic LINQ OrderBy on IEnumerable<T> and also Dynamic LINQ.

They are all awesome. I decided to try Dynamic LINQ by adding it through Nuget. However, I soon found that Dynamic LINQ only support property names. In some cases, we want to be able to sort by specifying column attribute value, so I still use my own code which works just fine although it might not be optimized for performance.

For example in VB.NET:

Public Class Customer
    <Column c_name="">
    Public Property Name As String

    <Column c_age="">
    Public Property Age As Integer
End Public

Dim sortedByName = dbContext.Customers.AsEnumerable().SortBy("c_Name, c_Age DESC")

The gist for my code can be found in:
https://gist.github.com/nikyodo85/202fc2d417d9eb030d30896ccc862b7d

Comments

Popular posts from this blog

Sentinel One Strikes Again. No internet connection. Uninstall Sentinel One Agent.

A2 Hosting Let's Encrypt Can't Install Certificate on ASP.NET Core Application

NuGet Package Reference NU6105 Publish Error