我的控制器视图
foreach (var dbItem in db1.Ranges.Where(x => x.DeviceId == Id).OrderByDescending(x => x.DeviceTime))
{
list.Add((double)dbItem.Val1);
}
我的数据库行 - > Database Table
正如您所看到的,DB中有很多行,但是当我运行它时,我只得到1行。
答案 0 :(得分:1)
您可以尝试:
var items = db1.Ranges
.Where(x => x.DeviceId == Id)
.OrderByDescending(x => x.DeviceTime)
.Select(x => x.Val1)
.ToList();
// if list is a List<double>
list.AddRange(items.Select(x => (double)x));
// If you really need the foreach
foreach(var value in items)
{
list.Add((double)value);
}