LINQ Dynamic Query Library


 

Example

Instead of using language operators or type-safe lambda extension methods to construct your LINQ queries, the dynamic query library provides you with string based extension methods that you can pass any string expression into.

For example,

Using the LINQ DynamicQuery library I could re-write the above query expression instead like so:

Notice how the conditional-where clause and sort-orderby clause now take string expressions instead of code expressions.  Because they are late-bound strings I can dynamically construct them.  For example: I could provide UI to an end-user business analyst using my application that enables them to construct queries on their own (including arbitrary conditional clauses).

Download Dynamic Query Library & Documentation

C# Dynamic Query Library (included in the \LinqSamples\DynamicQuery directory)

You can copy/paste either the C# or VB implementations of the DynamicQuery library into your own projects and then use it where appropriate to more dynamically construct LINQ queries based on end-user input.

Via Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library) – ScottGu’s Blog

About these ads

3 thoughts on “LINQ Dynamic Query Library

  1. I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to construct my own blog and would like to find out where u got this from. appreciate it

  2. Good Article but in my requirement i need to get values from 2 different tables which have 0,1 -> * Relation ship (so i can not use Include statement). can you give me an example how to write dynamical query for the above scenario??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s