var lastArticles = from a in be.MyTable
where a.id == 1
join c in be.OtherTable on a.parent equals c.id
orderby a.timestamp descending
select new { a, cName = c.name};
我需要获取前5个元素。
我正在做
.Take(5)
但是在linq语句中有办法吗?
最佳答案
不,您需要使用Skip()
和Take()
作为方法调用。没有特定于LINQ的等效项。
var lastArticles = (from a in be.MyTable
where a.id == 1
join c in be.OtherTable on a.parent equals c.id
orderby a.timestamp descending
select new { a, cName = c.name }).Take(5);
关于c# - 修改linq以获取前5个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10123913/