LINQ To SQL: Distinct operator

EmpDetails Table:

LinqTable.png


Code:


To eliminate duplicate elements from 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<String> empQuery = (from emp in dc.EmpDetails
                               select emp.Dept).Distinct();

foreach (String dept in empQuery)
{
Console.WriteLine(dept);
}
Console.ReadLine();
}
}
}

Distinct.png
Ebook Download
View all
Learn
View all