c# - Skip/Take Missing 的 Lambda 过载

标签 c# linq entity-framework-6

我正在运行一些非常简单的测试代码来查看常量在 linq 查询中的影响,但我无法找到过载...

This MSDN article特别提到了 skip/take 的 lambda 重载,但我似乎找不到它。

来自 Performance Considerations for Entity Framework 4, 5, and 6 的第 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."

他们遵循此代码示例:

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

我的测试代码:

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

我是否无法阅读,或者重载的扩展方法是否在某处缺少包含?我正在使用 EF 6.1.1。

最佳答案

您要查找的扩展方法是“QueryableExtensions.Skip”。它位于 EntityFramework 程序集中的 System.Data.Entity 命名空间中。

关于c# - Skip/Take Missing 的 Lambda 过载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24947556/

相关文章:

c# - 给定以下 linq 查询,哪一个是 'more performant' ?

c# - Entity Framework DbContext 执行的日志查询

c# - 如何为 PLINQ 重新实现 Where() 运算符?

c# - 为什么要为初始化器烦恼? (。网)

performance - LINQ 使用带有 Count 和Where 的 Group,简单的 SQL,在 LINQ 中更难

c# - 导航属性 Project.Models.Customer.SubCustomers 的声明类型与指定导航的结果不兼容

c# - 是否可以将单个 linq 查询结果分配给多个变量?

c# - 使用手动事务和分层事务进行单元测试

c# - 在 ASP.NET 中为特定页面设置无缓存?

c# - 合并多个列表