Pages

Monday, March 4, 2013

LINQKit is good and more people should use it

If I had to pick one library that is criminally underused in the C#/.NET world, it would be LINQKit.  A library for making it easier to manipulate and work with expressions (most often used in conjunction with LINQ).

I think part of the reason it's underused is because it's basically 100% complete, a few years old, and you can easily live without it; though I'll try to convince you that you don't want to.  LINQKit is boring because it does one thing and its been doing it for years already.  But it is horribly underused from what I've seen.

LINQKit is has become almost an automatic addition to .NET projects I start.  Most of the time I start a medium sized or bigger C# project, I 'install-package LINQKit'

Which helps bring me to my next point.  I'd make the bold statement that if you have an app that's >50,000 lines of code and it's heavy on data access/Entity Framework/lambda expressions, chances are your codebase could be cleaned up and DRYed out if you used LINQKit.  I decided to write this article because  few people seem to use it and I have a friend working on a commercial project that would be cleaned up by LINQKit because it's very expression heavy (unfortunately one of the project requirements is no 3rd party libraries).  It has me wondering how many coders are unaware of this awesome library.


Only 13,000 NuGet downloads.  1.2 Million for Entity Framework!

I considered making a code example for this post but decided against it.  There are many of short examples that will illustrate the usefulness to you.

Here are a few links with convincing examples of LinqKit usage

3 comments:

  1. I am building a project that targets .net framework 4.0 due to which nuget is not installing it..please help me out because i really need to work with predicate builder for dynamic LINQ

    ReplyDelete
  2. Did you add Using LinqKit; to the top of any file that wants to scope in that namespace? Are you sure you have the right project selected to install it under? Maybe you are accidentally installing it into a test project or the incorrect project. If that doesn't work, I need more information and then I can help you.

    Also, you can use plain SQL in entity framework now and deserialize as an object. Expression rewriting is sometimes unnecessary.

    ReplyDelete