Expression Trees as the basis for user defined query engine (using EAV)?
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:
Custom Date Field < DateTime.Today
开发者_C百科And
Custom Number Field1 > 1000 and < 1500
Or
- 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?
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
Be sure to check out the Dynamic LINQ Query Library as another option. It's popular and powerful.
精彩评论