LinQ Query Helper

Building a dynamic LinQ query for every entity or a collection is tedious and complex for maintenance. Based on my previous experience and challenges faced in applications, I have come up with a solution to build dynamic expressions for generic entities or collection. This solution will enable users

  • To perform dynamic “order by” by building generic expressions.
  • Generate dynamic expressions using expression builder.
  • Join expressions with “And” and “Or” operators on any layers of the application.
  • Able to build and execute dynamic generic expressions on database entities as well as other local collection entities.
  • Proper error handling.
  • A generic LinQ solution to the entire application.

This solution is packed as dll and hosted in nuget. Use “Package Manager Console” in Visual Studio and run the below command

Install-Package LinqQueryHelper.dll

Nuget Link: https://www.nuget.org/packages/LinqQueryHelper.dll

For dynamic query on a single entity or a similar group of entity collection we can also use Linq Dynamic Query Library (“System.Linq.Dynamic”) which was beautifully explained in ScottGu’s blog. But this fails on handling dynamic queries and expressions when joins come in to picture.

This solution overcomes all these challenges and provides a very flexible and simple methods to build dynamic expressions and generic query ability on all type of LinQ queries (including joins).

Your feedback is very important. Please comment if this solution works for you and recommend improvements.

 

Leave a comment