LINQ为了通过聚集在选择{}

编程入门 行业动态 更新时间:2024-10-20 11:43:53
本文介绍了LINQ为了通过聚集在选择{}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这里有一个我的工作:

var fStep = from insp in sq.Inspections where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime && insp.Model == "EP" && insp.TestResults != "P" group insp by new { insp.TestResults, insp.FailStep } into grp select new { FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0), CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0), grp.Key.TestResults, grp.Key.FailStep, PercentFailed = Convert.ToDecimal(1.0 * grp.Count() /tcount*100) } ;

我想排序依据在选择投影领域的一个或多个。

I would like to orderby one or more of the fields in the select projection.

推荐答案

最简单的变化可能是使用查询延续:

The simplest change is probably to use a query continuation:

var fStep = from insp in sq.Inspections where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime && insp.Model == "EP" && insp.TestResults != "P" group insp by new { insp.TestResults, insp.FailStep } into grp select new { FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0), CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0), grp.Key.TestResults, grp.Key.FailStep, PercentFailed = Convert.ToDecimal(1.0 * grp.Count() /tcount*100) } into selection orderby selection.FailedCount, selection.CancelCount select selection;

这主要是相当于用让,说实话 - 真正的区别是,让引入了的新的的范围变量,而查询延续有效地启动一系列变量的新天地 - 你不能后参考 GRP 位在进入选择例如

That's mostly equivalent to using "let", to be honest - the real difference is that let introduces a new range variable, whereas a query continuation effectively starts a new scope of range variables - you couldn't refer to grp within the bit after into selection for example.

这是值得注意的是,这是的究竟的一样使用两个语句:

It's worth noting that this is exactly the same as using two statements:

var unordered = from insp in sq.Inspections where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime && insp.Model == "EP" && insp.TestResults != "P" group insp by new { insp.TestResults, insp.FailStep } into grp select new { FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0), CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0), grp.Key.TestResults, grp.Key.FailStep, PercentFailed = Convert.ToDecimal(1.0 * grp.Count() /tcount*100) }; var fStep = from selection in unordered orderby selection.FailedCount, selection.CancelCount select selection;

更多推荐

LINQ为了通过聚集在选择{}

本文发布于:2023-11-22 05:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!