2010-04-28 164 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);