I have a SQL query of the following type and I was trying to fetch the data in my C# application using LINQ
select
sum(CASE when outcome = 0 then samplingweight else 0 end) tpcount,
sum(CASE when outcome = 1 then samplingweight else 0 end) fpcount,
sum(CASE when outcome = 2 then samplingweight else 0 end) mismatch,
sum(CASE when outcome = 3 then samplingweight else 0 end) fncount,
sum(CASE when outcome = 4 then samplingweight else 0 end) tncount,
sum(samplingweight) totalweight,
__date,
scenario from MyTable
where __date = '30-Dec-16 12:00:00 AM' and scenario = 'parcels'
group by __date, scenario
NOTE: samplingweight is a double value in DB.
I was trying and was able to reach to the below state
from pr in this.context.ComputedPrSet
where
pr.Date.Equals(date) && pr.Scenario.Equals(scenario)
group pr by new { pr.Date, pr.Scenario }
into grp
select new
{
grp.Key.Date,
grp.Key.Scenario,
TruePositiveCount = grp.Sum(x => x.SamplingWeight) //I am stuck here. Not sure how to aggregate the properties
};
NOTE: date and scenario in the above LINQ query are taken as parameters to the executing function.
Any ideas or tips on how to proceed?
grp.Where(x => x.outcome == 1).Sum(x => x.SamplingWeight)