Question

I'm trying to use ServiceStack OrmLite's Db.Select<T> method to execute an arbitrary SQL fragment that works just fine when run against the database directly. Instead, I'm getting a SqlException out of their stack.

var res = Db.Select<Foo>(@"
  declare @v int = 1;
  select f.* from Foo where 1=@v;");

I'm generating the text at run time, and cannot use LINQ expressions. I just want to know why this works against my database, works with a regular SqlDbConnection, but blows up in ServiceStack's OrmLite. Can I disable whatever unhelpful parsing that they must be doing?

Was it helpful?

Solution

Use OrmLite's raw db.Sql* API's for querying raw SQL, e.g:

var res = Db.SqlList<Foo>(@"
  declare @v int = 1;
  select f.* from Foo where 1=@v;");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top