Forum


HomeHomePremiumPremiumDevelopmentDevelopmentDAL2 - CountDAL2 - Count
Previous
 
Next
New Post
12/20/2013 7:22 AM
 

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

I want perform queries such as:

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

The information I come across only includes examples that allow the user to specify the WHERE part of the SQL.  This example unfortunately skirts right around the WHERE part of the query so I am not sure how I should approach this using DAL2.  Is it possible using DAL2 and if so, how do I execute such a query?

 

Thanks

 
New Post
12/20/2013 10:14 AM
 

Andy,

My thought on this is...

Let's say you have a ProductType class which is your DAL2 model.  You create another class that is just a simple POCO.  

Example:

    public class ProductTypeSummary
    {
        public int ProductType { get; set; }
        public int ProductTypeCount { get; set; }
    }

Inside your ProductType DAL Repository class, you can add a method like:

     public IEnumerable<ProductTypeSummary> GetProductTypeSummary()
     {
            using (IDataContext ctx = DataContext.Instance())
            {
                return ctx.ExecuteQuery<ProductTypeSummary>(System.Data.CommandType.Text,
                    "SELECT ProductType, COUNT(*) AS ProductTypeCount FROM Products GROUP BY ProductType");
            }  

     }

I haven't tested this obviously, but I think it should work.

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentDAL2 - CountDAL2 - Count



Try FREE
30 days money back guaranteed