我有以下LINQ查询:
private int x1;
private int x2;
private int y1;
private int y2;
public Slope(int a, int b, int c, int d) {
y2 = d;
y1 = c;
x2 = b;
x1 = a;
System.out.println(x1 - x2 / y1 - y2);
}
public static void main(String[] args) {
Slope slope = new Slope(70, 80, 1, 2);
}
目标是指定应该获取的行范围。我想用List<Person> people =
db.People.Take(pageSize)
.OrderByDescending(t => t.Id)
.ToList();
语句来做。问题是如何将特定的行索引放入where
语句?
这样的事情:
where
答案 0 :(得分:1)
您可以使用skip
和take
,如下所示:
List<Person> people = db.People
.Skip(pageSize * pageNumber).Take(pageSize)
.OrderByDescending(t => t.Id)
.ToList();
答案 1 :(得分:0)
public static List<Person> GetPeopleRange(int pageSize, int startIndex, int endIndex)
{
using (var db = new MyEntities())
{
return (from p in db.People
.Where(p => p.Id >= startIndex && p.Id < endIndex)
select p).Take(pageSize).OrderByDescending(p => p.Id).ToList();
}
}