如何在Linq Foreach语句中添加where子句? 这是我的Linq:
@foreach (var item in Model.Select(x => new
{
Rid = x.Rid,
Total = x.Total
})
.GroupBy(l => l.Rid) //and then grouping
.Select(z => new
{
Turno = z.Key,
Total = Decimal.Round(z.Sum(l => l.Total), 0)
}))
{
<input value="@item)" />
}
我想在where子句中使用where子句来评估一个名为&#39; Date&#39;的全局变量,我是Linq的新手,那么我该怎么办呢?
答案 0 :(得分:3)
假设它不属于Model类,那只是
@foreach (var item in Model.Where(x => x.Date == this.Date)
.Select(x => new
{
Rid = x.Rid,
Total = x.Total
})
.GroupBy(l => l.Rid) //and then grouping
.Select(z => new
{
Turno = z.Key,
Total = Decimal.Round(z.Sum(l => l.Total), 0)
}))
{
<input value="@item)" />
}
这将按日期过滤模型。如果您的日期变量命名不同,显然只需更改它。