views:

33

answers:

1

I'm supporting a multi-tenant system that allows users to define custom forms. The data model is EAV based because issuing dynamic DDL to change table schema doesn't work when supporting multiple tenants in a single DB. An upcoming requirement is to build a flexible query designer that allows users to setup simple predicates against the custom forms they've defined:

  1. Custom Date Field < DateTime.Today

    And

  2. Custom Number Field1 > 1000 and < 1500

    Or

  3. Custom Number Field2 Is Null

I had intended to build this query engine by dynamically spooling SQL strings, but I wonder if Expression Trees offer a more testable and type-safe approach. Is this a good application for ETs?

A: 

Yes, utilizing expression trees would be a much better/easier way to approach dynamic user-defined queries. This simple class can greatly help building up dynamic queries:

PredicateBuilder

Ocelot20