开发者

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:

  1. Custom Date Field < DateTime.Today

    开发者_C百科

    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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜