Colin Mackie - 382 - Nov 6, 2014

Can anyone point me at a good example of using OrmLite with UNION? I searched around but couldn’t find anything.

I am trying to select a few common fields from a few tables . I know I could just build and exec the whole SQL statement, but I am trying to create an SqlExpression object so I can attach an OrderBy, Limits, etc.

For example, here is a simple version of the SQL:

select id, name from Person
union select id, Name from Place
where Name like '%mackie%'
order by Name

What I don’t know is the best way to create the SqlExpression so my like and order can be dynamic.

e.g. something like (I know it’s not right)

var query = Db.From<Place>().Union<Person>();
query.Where(“Name like {0}”, “Mackie”);

Colin Mackie:

Ok, thanks, will do.

Out of interest is that a limitation or just not implemented, and if so, would it likely be anytime?

OrmLite typed SQL Expressions doesn’t support union, you’ll have to drop down to custom SQL to use it.

It’s just not implemented, you can add a feature request for it at:

Please include an API example of what you want it to support.