How to use Count (*) with DAL2?

I want to get counts for various data groupings in some of my tables and am not sure if this is possible with DAL2.

I want to fulfill queries such as:

SELECT  DISTINCT productType, COUNT(*) FROM Products GROUP BY productType

The information I come across includes only examples that allow the user to specify the WHERE SQL part. This example, unfortunately, skirts right around the WHERE query part, so I'm not sure how I should approach this with DAL2. Is it possible to use DAL2 or do I need to query the database differently? If this can be done using DAL2, how can I execute such a query?

+4
source share
2 answers

, WHERE, , PetaPoco "SELECT * FROM TableName" , , , SQL-

:

public class ProductCount {
   public int ProductType {get; set;}
   public int Count {get; set;}
}

var ProductCountList = db.Fetch<ProductCount>(@"SELECT DISTINCT productType, 
        COUNT(*) as Count 
        FROM Products 
        GROUP BY productType");
+3

, . SQL- dal2 dnn. SQL- , ( ) false. , . , , .

.

0

All Articles