Sự thay đổi đơn giản nhất có lẽ là sử dụng một sự tiếp nối truy vấn:
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;
Đó là chủ yếu là tương đương với việc sử dụng "phép", phải trung thực - sự khác biệt thực sự là để điều đó giới thiệu một mới phạm vi biến, trong khi tiếp tục truy vấn có hiệu quả bắt đầu phạm vi biến phạm vi mới - bạn không thể tham khảo grp
trong bit sau into selection
chẳng hạn.
Nó đáng chú ý rằng đây là chính xác giống như cách sử dụng hai báo cáo:
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;
Nguồn
2010-03-31 20:37:51
Hoạt động tốt –
điều này rất tốt. công việc tốt, jon –