Home > Mobile >  How convert this SQL query to linq?
How convert this SQL query to linq?

Time:12-26

I have this SQL query and I want to convert it to linq:

SELECT
    SUM(CASE WHEN AsiDurumu = 1 THEN 1.0 ELSE 0.0 END) / MAX(CovidId) 
FROM Covids

CodePudding user response:

If you need several aggregation expressions in one non-grouping LINQ Query, you should GroupBy by constant. EF has special translation for such cases.

var query = 
    from c in ctx.Covids
    group c by 1 into g
    select new 
    {
        Some = g.Sum(x => x.AsiDurumu == "1" ? 1 : 0) / g.Max(x => x.CovidId)
    };
  • Related