Lions Den

The Code and Times of Hanan Schwartzberg

About Hanan | Hanan's CV | Contact Hanan

March 16, 2009

Conditional Where in LINQ

Filed under: C#,LINQ — Tags: , , , — Hanan Schwartzberg @ 11:38 pm

Recently I needed to build a LINQ query with a conditional where clause. After a bit of searching I found a few solutions. In essence they all seem to come down to two methods. The first method is to run a second LINQ query to filter the results from the first one. The second method is to run a totally separate LINQ query for each scenario. In deciding which to use I wrote a test program that pit these two methods against each other and found that the latter was noticeably more efficient (when running the query 5000 times).


Home | Site Design | Banner Design | Code Den | Offsite Posts | Downloads | Photography | About Hanan | Hanan's CV | Contact Hanan
Copyright © 2009 Hanan Schwartzberg. All rights reserved.