Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda overload for Skip/Take Missing

I was running some very simple test code to look at the effects of constants in linq queries and I'm having trouble locating an overload...

This MSDN article specifically mentioned a lambda overload for skip/take, however I can not seem to locate it.

From Section 4.2 of Performance Considerations for Entity Framework 4, 5, and 6:

"In particular pay attention to the use of Skip and Take when doing paging. In EF6 these methods have a lambda overload that effectively makes the cached query plan reusable because EF can capture variables passed to these methods and translate them to SQLparameters."

They follow that with this code sample:

var customers = context.Customers.OrderBy(c => c.LastName);
for (var i = 0; i < count; ++i)
{
    var currentCustomer = customers.Skip(() => i).FirstOrDefault();
    ProcessCustomer(currentCustomer);
}

My test code:

for(int i = 0; i<100; i++)
{
    var result = dc.Products
                 //.Select(p => p.Name)
                   .OrderBy(p => p.Name)
                   .Skip(() => i)
                   .ToList();
}

Error: Cannot convert lambda expression to type 'int' because it is not a delegate type

Am I failing at reading, or is there an include missing somewhere with the overloaded extension method? I'm on EF 6.1.1.

like image 372
Kelly Robins Avatar asked Jul 25 '14 03:07

Kelly Robins


1 Answers

The extension method you're looking for is "QueryableExtensions.Skip". It's in the System.Data.Entity namespace, in the EntityFramework assembly.

like image 89
porges Avatar answered Oct 10 '22 12:10

porges