Lambda overload for Skip/Take Missing

c# entity-framework-6 linq

Question

I'm having problems finding an overload while running some very basic test code to examine the implications of constants in linq queries.

I am unable to find the lambda overload that This article from MSDN specifically indicated for skip/take.

Quoting from Considerations for Entity Framework 4, 5, and 6 Performance Section 4.2:

"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 then provide the following code example:

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 program:

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

Is the overloaded extension method lacking an include someplace, or am I just bad at reading? On EF 6.1.1 I am.

1
7
7/25/2014 3:39:13 AM

Accepted Answer

"QueryableExtensions.Skip" is the extension technique you're looking for. The is in theSystem.Data.Entity in the EntityFramework assembly's namespace.

15
7/25/2014 3:34:51 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow