C# 将SQL查询转换为Linq
有人能帮我把sql查询转换成LINQ吗?我很了解SQL查询,但我是Linq的新手。非常感谢你对我的帮助C# 将SQL查询转换为Linq,c#,linq,postgresql,C#,Linq,Postgresql,有人能帮我把sql查询转换成LINQ吗?我很了解SQL查询,但我是Linq的新手。非常感谢你对我的帮助 SELECT subConsulta."NitIps", subConsulta."NumFactura", COUNT(*) FROM (SELECT DISTINCT acf."NitIps", acf."NumFactura", acf."TipoSoporte"
SELECT
subConsulta."NitIps",
subConsulta."NumFactura",
COUNT(*)
FROM
(SELECT
DISTINCT acf."NitIps",
acf."NumFactura",
acf."TipoSoporte"
FROM
"t_ArchivoCentralFacturacion" AS acf
inner join "t_TRCompartaTiposDocumentalesAC" AS ctd
on
acf."TipoSoporte"= ctd."Id"
GROUP BY
acf."NitIps",
acf."NumFactura",
acf."TipoSoporte")as subConsulta
GROUP BY
subConsulta."NitIps",
subConsulta."NumFactura"
ORDER BY
subConsulta."NitIps",
subConsulta."NumFactura"
如果将表映射到实体,则如下所示:
var first = from archivoCentralFacturacion in ArchivoCentralFacturacions
group archivoCentralFacturacion by new {
c.NitIps,
c.NumFactura,
c.TipoSoporte
} into subConsulta
select subConsulta;
var result = (from f in first
group f by new {
f.NitIps,
f.NumFactura
} into r
select new {
NitIps = r.NitIps,
NumFactura = r.NumFactura,
ResultCount = r.Count()
}).OrderBy(x => x.NitIps).ThenBy(x => x.NumFactura);