简体   繁体   中英

Add a Linq clause to a Iqueryable object

I have a method who get a Iqueryable object get from a LINQ Query On this object, i want to add a LINQ clause : .skip(20) How can i do that from my method ?

Thanks by advance

您不能向现有查询中“添加”一个子句,因为查询本身是不可变的-但您可以创建一个查询,该查询是现有查询,但带有一个附加子句:

IQueryable<Foo> newQuery = oldQuery.Skip(20);
var query = FunctionThatReturnsIQueryable().Skip(20);

As long as you haven't enumerated over the query, you can always add clauses. The clauses are only executed as soon as you get the results (eg with for each ).
You could do something like GetSomeIQueryable().Skip(20) . That returns you a new query that includes your skip clause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM