What's the Linq to SQL equivalent for CEILING?
3 answers
Many .NET methods are converted to SQL Server functions, such as most of the Math class methods and the String class. But there are some caveats .
Also consider the SqlMethods class , which provides additional SQL Server functionality that has no .NET equivalent.
But you don't even need anything in your case:
int numberOfPages;
using (var db = new MyDBDataContext())
{
numberOfPages = (int)Math.Ceiling(db.Books.Count() / 10.0);
}
+1
a source to share
I do not think that's possible. A possible solution would be to get the total and then figure it out in .NET code. Like below:
where the query is 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);
0
a source to share