我的程序从客户那里得到这个查询:
var productsQuery = context.Goods
.Select((p) =>
new {
Name = p.Name,
Type = p.Type,
BestBefore = p.BestBefore,
ShopId = p.ShopId
})
.Where((p) => p.Type == "Food");
这个查询的结果有超过 10000 条记录。我的目的是根据一个条件从此查询中获取索引和好对象:
// variable selectedShopId is given earlier
var productObject = productQuery
.AsEnumerable()
.Select((p, i) =>
new {
Index = i,
Product = p
})
.Where(p => p.Product.ShopId == selectedShopId)
.FirstOrDefault();
我试过 make AsEnumerable(),但它对我没有帮助。