以下的 LINQ 等效语句是什么?
SELECT FLOOR(Value / @Step) * @Step AS Bin,
COUNT(*) AS Cnt
FROM Measurements
WHERE (StepId = @StepId)
GROUP BY Bin
ORDER BY Bin
目前尚不清楚这些参数或列的来源,但假设 LINQ to SQL,这应该或多或少等效:
var step = ...;
var stepId = ...;
var query =
from m in dc.Measurements
where m.StepId == stepId
group m by m.Bin into g
orderby g.Key
select new
{
Bin = Math.Floor(Value / step) * step, // where did "Value" come from?
Cnt = g.Count(),
};
使用 Lambda 表达式:
var query = dc.Measurements.AsEnumerable().Where(x=>x.StepId=_stepId).
GroupBy(g=>g.Bin).Select(xg=>new
{
Bin = Math.Floor(Value / step) * step,
Cnt = xg.Count(),
}
);