How to do this query in EF Core?

68 Views Asked by At

I need to do this query in ef core:

count(cmt.CaptureMethodId) as Total,
sum(case when DeactivateDate is null then 1 else 0 end) as Active,
sum(case when DeactivateDate is not null then 1 else 0 end) as Inactive
from [dbo].[CaptureMethodTerminals] cmt
join [dbo].[MerchantCaptureMethod] mcm
on cmt.CaptureMethodId = mcm.CaptureMethodId
where mcm.ClientMerchantId in ('00020', '00025')
1

There are 1 best solutions below

5
Fixation On

Something like this

const ClientMerchantIds = new string[] {"00020", "00025"};
var cmt = dbContext.CaptureMethodTerminals.Where(x => ClientMerchantIds.Contains(x.CaptureMethod.ClientMerchantId));
var Total = cmt.Count();
var Active = cmt.Count(x => x.DeactivateDate == null);
var Inactive = cmt.Count(x => x.DeactivateDate != null);