Random ramblings about random stuff


This blog now supports HTTPS connections, thanks to the Let’s Encrypt initiative!

Almost there!

I’m currently working on my final papers for college. It has already been three years – next month I will be graduating. It seems odd that it has been so long, I can recall the day I started as if it were yesterday. Anyway that’s all :P

Dynamically accessing data fields in LINQ using Expression trees

For a certain project I’m working on I needed a way to filter data in a LINQ query (LINQ to Entities) based on input given by the user. The user has to be able to select a certain property and compare that to given values.

The property names are fetched from the entity class using reflexion and listed in a dropdown input control. The next step would be to somehow use the selected value in my LINQ query as a property name. That however didn’t seem to be so trivial at first .. until I discovered expression trees.

Expression trees allow you to build expressions in the same way that you can use Lambda to build expressions but on a more verbose/dynamic way. It allows you to continue where lambda expressions can’t go thus giving you much more power.