Waseem Sabjee

my tech and dev blog

LINQ Expression – how to append to an expression at a later stage

July 23rd, 2013

The cool thing with LINQ and Entity framework is that if you pass an expression through to you context, it creates an SQL Query based of that expression to fetch the data you need, instead of fetching loads of data down and having to sift through them in C#.

A recurring issue that plagued me was that if I needed to pass through a slightly different LINQ expressions based on certain conditions it looked like I was repeating code, and I don’t like repeating code.

after a few hours of playing around with different techniques I devised a little way to append to an expression.