I <3 LinqKit – Dynamically build arbitrarily complex Linq Queries

In some cases, I need to be able to build a query that has a variable set of OR conditions. This is not simple with the default language constructs and extension methods.

It’s simple to dynamically build an expression that includes AND parameters, because that is what the WHERE() extension method does. Not so easy for OR’ing together a bunch of conditions.

Enter LinqKit.

This is a great library. It provides some easy to use (but powerful) extension methods that let you “Or()” some conditions together. A common case is where you get a list of values that you need to add into the condition. You iterate over these and append them to an expression in a foreach() loop. Check out the LinqKit page for some great samples and explanations. I’d share some of my stuff, but their page is already awesome.

Cheers!

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

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: