EF Core:如何从数据库中获取 RowNumber?

问题描述 投票:0回答:0

我的程序从客户那里得到这个查询:

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(),但它对我没有帮助。

c# postgresql entity-framework memory-leaks linq-to-sql
© www.soinside.com 2019 - 2024. All rights reserved.