Search code examples
servicestackormlite-servicestack

Union all support in ServiceStack ORM lite 4.5.4


In my application user can define multiple filters for specific type. I would like to somehow combine these queries in single one.

SqlExpression<Notice> query1 = Db.From<Notice>(s=>s.param1 == 2);
// ...queries are more complicated but result type is same
SqlExpression<Notice> query2 = Db.From<Notice>(s=>s.param1 == 3 && s.param2 == 3);

SqlExpression<Notice> unionAll = query1.UnionAll(query2);
var result = Db.Select(unionAll);

Any idea how to implement this in Orm Lite (4.5.4)?


Solution

  • Whilst there's no official API that lets you do this, you should be able to construct it with something like:

    var sql = query1.ToSelectStatement()
              + " UNION ALL " +
              query2.ToSelectStatement();
    
    var results = db.SqlList<Notice>(sql);