LINQ To SQL: Count operator

EmpDetails Table:


LinqTable.png


Code:

To count the number of elements in the 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();
int empCount = (from emp in dc.EmpDetails
                select emp).Count();
Console.WriteLine(empCount);
Console.Read();
}
}
}


Alternate Method:


DataClassesDataContext dc = new DataClassesDataContext();
int empCount = dc.EmpDetails.Count();
Console.WriteLine(empCount);
Ebook Download
View all
Learn
View all