TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
LINQ To SQL:Take<TSource> operator
Vijai Anand Ramalingam
Jun 20, 2011
3.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog we will be seeing how to return a given number of elements in a sequence
EmpDetails Table:
Code:
To return a given number of elements in a sequence
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LINQ
{
class
Program
{
static
void
Main(
string
[] args)
{
DataClassesDataContext
dc =
new
DataClassesDataContext
();
IQueryable
<
EmpDetail
> empQuery = (
from
emp
in
dc.EmpDetails
select
emp).Take(2);
foreach
(
EmpDetail
empDetail
in
empQuery)
{
Console
.WriteLine(
"ID :{0}, Name :{1}, Location :{2}, Department :{3}"
, empDetail.ID, empDetail.Name, empDetail.Location, empDetail.Dept);
}
Console
.ReadLine();
}
}
}
Output:
Returns the first two data from the EmpDetails table as shown in the following
Note:
IQueryable
<
T
> interface :
Provides functionality to evaluate queries against a specific data source wherein the type of the data is known.
Next Recommended Reading
LINQ To SQL: Sum operator