2010-04-28 103 views

回答

1

許多.NET方法將被轉換爲SQL Server的功能,如大多數的數學類和String類的方法。但有some caveats

另請參閱SqlMethods class,該文件公開了其他SQL Server功能,該功能沒有.NET等價物。

但在你的情況下,你甚至不需要任何的是:

int numberOfPages; 

using (var db = new MyDBDataContext()) 
{ 
    numberOfPages = (int)Math.Ceiling(db.Books.Count()/10.0); 
} 
0

你不使用SQL CEILING,你在你的LINQ查詢中使用.NET ceiling(Math.Ceiling)。

0

我不認爲這是可能的。 一個可能的解決方案是獲得總數,然後在.NET代碼中找出它。 象下面這樣:

,其中查詢是IQueryable的

var itemsPerPage = 10; 
    var currentPage = 0; 
    var totalResults = query.Count(); 
    var myPagedResults = query.Skip(currentPage).Take(itemsPerPage); 
    var totalPages = (int)Math.Ceiling((double)totalResults/(double)pageSize);