2011-01-31 15 views
1

我正在測試SubSonic,但我堅持我的第一個簡單例子。我有我試圖獲取10個最新的結果的消息表:簡單亞音速例子的sql錯誤

var newsItems = News.GetPaged("datecreated", 0, 10); 

這導致了這個錯誤:

[MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 6] 

生成的SQL:

SELECT `newsid`, `datecreated`, `headline`, `body`, `link`, `picture`, `linkinfo`, `postedby`, `comments`, `category` FROM news ORDER BY newsid DESC LIMIT -10,10 

這很容易手動修復SQL,但我不知道如何讓SubSonic自動爲查詢添加正確的LIMIT。任何指針?

回答

0

極限應該是一個正整數,從0開始-10,10不

http://dev.mysql.com/doc/refman/5.0/en/select.html

LIMIT -The子句可以用來限制由SELECT語句返回的行的數目。 LIMIT需要一個或兩個數字參數,它們都必須是非負整數常量(除了使用預準備語句時)。

生成的SQL應該已經

SELECT `newsid`, `datecreated`, `headline`, `body`, `link`, `picture`, 
    `linkinfo`, `postedby`, `comments`, `category` 
FROM news ORDER BY newsid DESC LIMIT 10; 

我認爲Subsonic你需要這個

var newsItems = News.GetPaged("datecreated", 1, 10); 
+0

謝謝!我以爲pageIndex是零.. – Vidar 2011-01-31 21:02:38