(COUNT(*) OVER()) in LINQ RRS feed

  • Question

  • SELECT  *, (COUNT(*) OVER()) AS TotalRows 
    FROM TableName
    WHERE Name like '%test%'
    Order By Name
    OFFSET  ((@pPageNumber -1) * @pPageSize)  ROWS 

    Above single query helps in pagination and also give the last column with Total Rows that helps in finding number of pages.

    Is there any way to samething with Linq ? I have used skip and take, but cant get total rows with single query ?

    Tuesday, November 18, 2014 3:22 AM


  • Hello Kberawala,

    Please have a try with below LINQ using a nested sub query:

    using (DFDBEntities db = new DFDBEntities())
                    var result = (from od in db.OrderDetails
                                  group od by od into newod
                                  select new { newod.Key, TotalRows = db.OrderDetails.Count() }).ToList();


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 18, 2014 9:24 AM