gpt4 book ai didi

c# - Skip/Take Missing 的 Lambda 过载

转载 作者:太空狗 更新时间:2023-10-29 19:59:39 28 4
gpt4 key购买 nike

我正在运行一些非常简单的测试代码来查看常量在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com