문제

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?

도움이 되었습니까?

해결책

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;");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top