0

如何使用 Lambda 在 Linq 中转换以下查询?

SELECT DISTINCT Registro, COUNT(Registro) as qnt 
FROM XML_Relatorio
WHERE Arquivo = 'redenet.xml' 
AND TipoErro <> 'Imovel Inserido' 
AND TipoErro <> 'TI'
AND DataHora BETWEEN '01-01-2012' AND '02-01-2012' 
GROUP BY Registro 
ORDER BY Registro

我正在尝试以下代码,但我需要一些帮助来使用 Lambda 构建 LINQ

IQueryable<XML_Relatorio> quantidadeErro = db.XML_Relatorios
    .Where(a => a.Arquivo == "redenet.xml" 
           && a.TipoErro != "Imovel Inserido" 
           && a.TipoErro != "TI");
4

1 回答 1

1

假设DataHora字段是DateDateTime类型。

// parse the strings to datetime 
var start = DateTime.Parse("01-01-2012");
var end = DateTime.Parse("02-01-2012");

IQueryable<XML_Relatorio> quantidadeErro = db.XML_Relatorios
   .Where(a => a.Arquivo == "redenet.xml" 
       && a.TipoErro != "Imovel Inserido" 
       && a.TipoErro != "TI"
       // and compare them...
       && a.DataHora > start && a.DataHora < end);
于 2012-09-04T18:34:25.543 回答