Evgeni
Evgeni

Reputation: 3353

OrmLite and Common table expressions

I'm trying to run a similar query:

sql = @"with t(id) as (select 1 )
select * from Project 
where id > (select id from t)";

var projects = this.Db.Query<Project>(sql).ToArray();

For some reason the OrmLite decides to treat the sql as as "where" clause, so what ends up running is something like this:

select field1, field2 from project where with t(id) .....

Does it look for a "select" at a starting position of the query ? Short of creating a view - is there a way to run query with CTE ?

Upvotes: 4

Views: 490

Answers (1)

mythz
mythz

Reputation: 143409

Use the db.Sql* API's for raw SQL Queries, e.g:

var projects = db.SqlList<Project>(sql);

Upvotes: 6

Related Questions