In this article I am going to explain the Take and Skip operators in LINQ to SQL. The Take operator is used to return a given number of rows from a database table and the Skip operator skips over a specifed number of rows in a database table.
1. Create a Data Context Class
I create a data context class that has tables or a stored procedure. One figure shows the EMPLOYEE table in a data context class and another all employee data in the database. This EMPLOYEE object has a relationship with the EMPLOYEE table.
2. Create UI Design
I use a GridView to show employee data. This GridView code is:
<asp:GridView ID="gridEmployee" runat="server" AutoGenerateColumns="false">
</asp:GridView>
3. Take Operator
The Take operator returns a specified number of contiguous rows from the starting point of the database table. The Take operator specifies how many rows we want from the start position of the table but when we define a criteria in that case this criteria is evaluated first before the start position is determined.
It works similar to the SQL TOP keyword where we get a specific number of contiguous top rows from a database table or can get top rows according to certain criteria.
The following code gets the top 5 rows from an EMPLOYEE object. It shows the top 5 rows from the EMPLOYEE table and shows them in the GridView.
private void GetEmployee()
{
EmployeeOperationDataContext employeeContext = new EmployeeOperationDataContext();
var employee = (from emp in employeeContext.EMPLOYEEs
select emp).Take(5);
gridEmployee.DataSource = employee;
gridEmployee.DataBind();
}
The following code gets the top 5 rows from an EMPLOYEE object. These employees have a salary greater than 1200. They are shown in a GridView.
private void GetEmployee()
{
EmployeeOperationDataContext employeeContext = new EmployeeOperationDataContext();
var employee = (from emp in employeeContext.EMPLOYEEs




Hải QuânPosted Dec 22, 2018, 8:40 AM
Can you run skip() and take() at the same time ?
Manish Kumar ChoudharyPosted Jan 18, 2015, 11:40 PM
Nice one..
Rakesh kumarPosted Jan 18, 2015, 11:15 PM
great bro.....
Punith NagarajPosted Aug 14, 2014, 11:59 PM
Super