Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Linq - how to add case when?

$
0
0

Hi,

I have this query below;

select count(status) AS 'NUMBER OF TIMES', CASE WHEN status = 0 THEN 'UNCERTAIN' WHEN status = 1 THEN 'CONFIRM' ELSE 'CANCEL' END AS STATUS
from GameConfirmResponses
group by status

I wonder if I can add case when to this;

var result = _context.GameBanks
                    .GroupBy(p => p.Status)
                    .Select(g => new
                    {
                        Count = g.Count(),
                        Status = g.Key 
                    }).ToList();

I tried this but I got syntax error.

Status = g.Key == 0 ? "UNCERTAIN": g.Key == 1 ? "CONFIRM" : g.Key == 1 ? "CANCEL"


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>