【发布时间】:2014-09-28 22:55:22
【问题描述】:
您好,这应该是一个与我不同的实际 LINQ 知识的非常简单的问题!我只想返回最后 20 条记录,通常是 .Take(20) 当按降序排序时,但因为我返回的是 model.CPU 的一个实例,所以我不知道该把语句放在哪里。
非常感谢您的帮助,过去一个小时左右一直在谷歌搜索。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
namespace hello_services.Controllers
{
public class cpuController : ApiController
{
private Data.ResourceDataModelDataContext _context = new Data.ResourceDataModelDataContext();
//WebAPI will respond to an HTTP GET with this method
public List<Models.CPU> Get()
{
//get all of the records from the Counter_CPU table
var cpuRecords = from e in _context.Counter_CPUs
select new Models.CPU
{
Counter_CPU_ID = e.Counter_CPU_ID,
//Counter_CPU_Time = e.Counter_CPU_Time,
Counter_CPU_Percentage = e.Counter_CPU_Percentage
};
return cpuRecords.ToList();
}
}
}
【问题讨论】:
-
为什么降序和
Take(20)不起作用?
标签: asp.net-mvc linq