0

Here I'm Writing simple Group by Class as

public IQueryable<Banker_Outward_Lock> GetcommedityDetails(string inwardreceipt)
{
    var x = from n in _Context.tbl_Commodity_Overview
            join _lock in _Context.tbl_bank_material_lock on n.co_user_registration_id equals _lock.bm_farmer_registration_id.ToString()
            where n.co_receipt_number == inwardreceipt
            group _lock by new { n.co_total_inward_quantity, n.co_balance_bags,_lock.bm_quantity,_lock.bm_No_Bags } into g
            select new Banker_Outward_Lock
                {
                    Quantity=g.Key.co_total_inward_quantity,
                    No_Bags=g.Key.co_balance_bags,
                    Locked_Qty=g.Key.bm_quantity,
                    Locked_Bags=g.Key.bm_No_Bags,
                    Balance_Qty=g.Sum(_lock=>_lock.bm_quantity),
                    Balnce_Bags=g.Sum(_lock=>_lock.bm_No_Bags),
                };

    return x;
}

This is my Sql Query which runnning fine

select n.co_receipt_number, n.co_total_inward_quantity, SUM(lock.bm_quantity) As Locked_Quantity, n.co_balance_bags, SUM(lock.bm_No_Bags) as lockedBags,
    SUM((n.co_total_inward_quantity) - (lock.bm_quantity)) as Balanced_Qty
from tbl_Commodity_Overview as n
JOIN tbl_bank_material_lock as lock on n.co_user_registration_id = lock.bm_farmer_registration_id
where co_receipt_number='KSWC-In-2050'
GROUP BY n.co_receipt_number,n.co_total_inward_quantity,n.co_balance_bags
                       

Why I am not able to get Sum result?

Please, help me where am I doing worng?

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76

0 Answers0