Dynamic Lambda Expression For Sorting A List / Collection Using Comple(www.jebarson.info)

submitted by jebarson007jebarson007(150) 9 months, 1 day ago

In my previous post we discussed on sorting the list / collection using dynamic lambda expression for properties. In this article we will see how to sort on complex properties. So what is a complex property. Consider the class diagram as shown below In our scenario, we have “Employee” entity, where we have a property “Department” which is a complex type. Now let us assume that we are binding the list of employees list along with the department name, then we will have to use item template along with “Bind” method called.

1 comment |category: |Views: 31

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by dpetersondpeterson(4397) 9 months ago 0

Are you binding to a ViewModel in this case? If so, you could simply add a property for DepartmentName returning Department.Name and sort on that, rather than using the complex Linq query.
Alternatively, you could implement SortOrder as a property on your viewmodel, and depending on certain bool fields, you could dynamically return a different property of the model as the sort string. Then you could always sort on the SortOrder property, and you retain the ability to do dynamic sorting.

Reply

information Login or create an account to comment on this story