C# 如何将linq从查询语法重新写入方法语法?
如标题所示,如何将此linq查询重写为方法语法C# 如何将linq从查询语法重新写入方法语法?,c#,linq,syntax,C#,Linq,Syntax,如标题所示,如何将此linq查询重写为方法语法 (from row in recordsEpP where (!string.IsNullOrEmpty(row.Column20) && !string.IsNullOrEmpty(row.Column14) && string.IsNullOrEmpty(row.Column8)) select new ReportDto{ Status = "P", C
(from row in recordsEpP
where (!string.IsNullOrEmpty(row.Column20)
&& !string.IsNullOrEmpty(row.Column14)
&& string.IsNullOrEmpty(row.Column8))
select new ReportDto{
Status = "P",
ContractNumber = row.ContractNumber,
Count = 1
}).ToList();
您可以尝试以下方法:
recordsEpP.Where(row=> !string.IsNullOrEmpty(row.Column20) &&
!string.IsNullOrEmpty(row.Column14) &&
string.IsNullOrEmpty(row.Column8)
).Select(row => new ReportDto{
Status = "P",
ContractNumber = row.ContractNumber,
Count = 1
}).ToList();
到目前为止有什么尝试吗?听起来很像是你让我们为你做的。我的问题是为什么<代码>recordsEpP.Where(…)。选择(…新建…).ToList()代码>没有降低复杂性,不容易阅读。谢谢@paqogomez,这只是为了了解。。。我刚开始学习linq,并提出了查询语法,但实际上并没有理解方法语法。。。你的例子说明得很清楚。再次感谢你