ServiceStack.OrmLite:哪里是编写自定义的SQL并获得结果集返回的方法? [英] ServiceStack.OrmLite: Where is the method to write custom SQL and get result set back?

查看:654
本文介绍了ServiceStack.OrmLite:哪里是编写自定义的SQL并获得结果集返回的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读上
https://github.com/ServiceStack/ServiceStack.OrmLite
找方法,这样我就可以执行正常的SQL(字符串命令),并得到一个结果集返回,但我不认为有任何

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.

我测试OrmLite v 4.0.17.0。

I am testing OrmLite v 4.0.17.0.

在上面的页面上有记载的方法的 SqlList 的,但我没有这样的方法可供选择:

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

我有一个的ExecuteSQL,但我没有得到任何结果集返回,只是一个int:

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

所以,有两个问题:


  1. 有没有办法来执行自定义查询,在一个字符串需要作为参数的方法,并在那里我再拿回一个结果集,行或对象或什么东西?

  2. 虽然我在这了,我怎么创建一个限制,例如SELECT * FROM一个LIMIT 10?

下面是版本信息:

推荐答案

是啊,我最近注意到,分贝。 SqlList 迷路在 OrmLite V4重构所以我已经恢复了它早在这次提交。这将是第4版的下一个版本可用,月底前。

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.

您仍然可以使用 db.Select 为原料SELECT查询,例如:

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'");

和自动加上SQL的其余部分给你,但是这是一个问题,当你不发出 SELECT 语句,如:调用存储过程,这是什么 db.SqlList 是因为原始SQL保持不变。

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.

用限制查询的另一种方法是使用输入表达式的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));

这篇关于ServiceStack.OrmLite:哪里是编写自定义的SQL并获得结果集返回的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆