Result Type of a SqlQuery RRS feed

  • Question

  • private List<DeptCount> GetDeptCount(Sale sale, Entities pse) { DeptCount deptCount = new DeptCount(); List<DeptCount> depCtList = new List<DeptCount>(); //issue is we are querying the SaleItems table for the current sale

    // - but returning only Count and Department //and not the full SaleItem object. That's why I created the

    //DeptCount obj but having trouble getting the results into the object var depCL = pse.SaleItems.SqlQuery("Select Count(Department) as

    Count, Department From SaleItems GROUP BY Department"); //foreach (SaleItem s in depCL) //{ // //do something like add to deptCount and add to depCtList //} return depCtList; }

    If I run this SQL in the it returns

    Count Department

    7 150

    2 190

    1 280


    So I created a class to hold the result

    class DeptCount
                private int Count { get; set; }
                private int Department { get; set; }

    I'd guess the actual result would be a list<DeptCount> depCtList but this

    doesn't seem to work and not sure why.

    • Edited by Mimosa Arts Wednesday, October 16, 2019 5:54 PM readability
    Wednesday, October 16, 2019 5:52 PM