-3

以下的 LINQ 等效语句是什么?

SELECT FLOOR(Value / @Step) * @Step AS Bin,
       COUNT(*) AS Cnt
FROM Measurements
WHERE (StepId = @StepId)
GROUP BY Bin
ORDER BY Bin
4

2 回答 2

1

目前尚不清楚这些参数或列的来源,但假设 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(),
    };
于 2012-05-30T00:03:15.070 回答
0

使用 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(),
    }
 );
于 2012-05-30T03:37:14.180 回答