Count 연산자를 사용하여 시퀀스의 요소 수를 계산합니다.
Northwind 샘플 데이터베이스에 대한 쿼리를 실행하여 91의 출력을 생성합니다.
예제
다음 예제에서는 데이터베이스의 Customers 수를 계산합니다.
Dim customerCount = db.Customers.Count()
Console.WriteLine(customerCount)
System.Int32 customerCount = db.Customers.Count();
Console.WriteLine(customerCount);
다음 예제에서는 데이터베이스에서 중지되지 않은 제품의 수를 계산합니다.
Northwind 샘플 데이터베이스에 대한 예제를 실행하여 69의 출력을 생성합니다.
Dim notDiscontinuedCount = Aggregate prod In db.Products _
Into Count(Not prod.Discontinued)
Console.WriteLine(notDiscontinuedCount)
System.Int32 notDiscontinuedCount =
(from prod in db.Products
where !prod.Discontinued
select prod)
.Count();
Console.WriteLine(notDiscontinuedCount);