GetDbCount question

Posts   
 
    
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 15-Mar-2012 11:13:21   

I am trying to understand why GetDbCount does not use Select Count to get the row count.

It seems that Select Count(*) or Select Count(Distinct SomeField) would be a more efficient query.

Why would I want to use this rather than GetScalar?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Mar-2012 12:14:48   

GetScalar is the generalized form, and GetDBCount is the special case.

In fact the following:

var cusomers = new EntityCollection<CustomerEntity>();
var count = adapter.GetDbCount(cusomers, null);

Produces a Select Count(*) as seen below.

Query: SELECT COUNT(*) AS NumberOfRows FROM (SELECT [Northwind].[dbo].[Customers].[Address], [Northwind].[dbo].[Customers].[City], [Northwind].[dbo].[Customers].[CompanyName], [Northwind].[dbo].[Customers].[ContactName], [Northwind].[dbo].[Customers].[ContactTitle], [Northwind].[dbo].[Customers].[Country], [Northwind].[dbo].[Customers].[CustomerID] AS [CustomerId], [Northwind].[dbo].[Customers].[Fax], [Northwind].[dbo].[Customers].[Phone], [Northwind].[dbo].[Customers].[PostalCode], [Northwind].[dbo].[Customers].[Region] FROM [Northwind].[dbo].[Customers]  ) TmpResult