ServiceStack.OrmLite: Where is the method to write custom SQL and get result set back?

不羁岁月 提交于 2020-01-13 20:21:15

问题


I have been reading on https://github.com/ServiceStack/ServiceStack.OrmLite to find methods so I can execute normal SQL (string commands), and get a result set back, but I dont think there is any.

I am testing OrmLite v 4.0.17.0.

On the page above, there is a method SqlList mentioned, but I have no such method available:

I have an ExecuteSql, but I get no result set back, just an int:

So, two questions:

  1. Is there a way to execute custom queries, a method that takes in a string as parameter, and where I then get back a result set, rows or objects or something?
  2. And while I am at it, how do I create a "LIMIT", for example "SELECT * FROM a LIMIT 10"?

Here is the version info:


回答1:


Yeah I recently noticed that db.SqlList got lost in the OrmLite v4 refactor so I've restored it back in this commit. Which will be available in the next release of v4, before the end of the month.

You can still use db.Select for raw SELECT queries, e.g:

var results = db.Select<Poco>("SELECT * FROM a LIMIT 10");

It's only an issue when it's not a SELECT statement because we'd assume it's short-hand like:

var results = db.Select<Poco>("Foo = 'bar'");

And automatically add the rest of the SQL for you, but this is a problem when you're not issuing a SELECT statement, e.g. calling a stored procedure, which is what db.SqlList is for since the raw SQL remains untouched.

Support for LIMIT in Typed Expression API

Another way to query with a limit is to use the typed expression API, e.g:

var results = db.Select<Poco>(q => q.Limit(10));


来源:https://stackoverflow.com/questions/19999864/servicestack-ormlite-where-is-the-method-to-write-custom-sql-and-get-result-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!