Have you ever wondered that how you could get the same effect of the LIMIT
clause in MySql in Linq?
Limit clause helps us to limit the number of records that can be fetched from database based on its count.
For example given a 'customerMaster
SELECT * FROM 'customerMaster ' LIMIT 0, 10
This will display the first 10 results from the database.
SELECT * FROM 'customerMaster ' LIMIT 5, 5
This will show records 6, 7, 8, 9, and 10.
Thus, it is really easier for us to create paginations, in various applications using MySql.
We can get the same effect by using LINQ. For this, we need to know two keywords, Skip and Take.
Consider the given example:
Given that '
' is a business object containing the elements of the table '
CustomerMaster customerMaster = new CustomerMaster();
List<CustomerMaster> _customerMasterList = customerMaster.GetAll();
var query = (from _customerMaster in _customerMasterList
clause actually bypasses a specified number of elements in a sequence and then returns the remaining elements and
returns a specified number of contiguous elements from the start of a sequence.
This helped to sort out my pagination problem. Hope it helps others too.