gpt4 book ai didi

linq - LINQ 中的行号

转载 作者:行者123 更新时间:2023-12-02 11:19:02 25 4
gpt4 key购买 nike

我有一个像这样的 linq 查询:

var accounts =
from account in context.Accounts
from guranteer in account.Gurantors
where guranteer.GuarantorRegistryId == guranteerRegistryId
select new AccountsReport
{
recordIndex = ?
CreditRegistryId = account.CreditRegistryId,
AccountNumber = account.AccountNo,
}

我想用 LINQ 返回的集合中当前行号的值填充 recordIndex。如何获取行号?

最佳答案

linq-to-entities 不支持行号。您必须首先从数据库中检索没有行号的记录,然后通过 linq-to-objects 添加行号。像这样的东西:

var accounts =
(from account in context.Accounts
from guranteer in account.Gurantors
where guranteer.GuarantorRegistryId == guranteerRegistryId
select new
{
CreditRegistryId = account.CreditRegistryId,
AccountNumber = account.AccountNo,
})
.AsEnumerable() // Moving to linq-to-objects
.Select((r, i) => new AccountReport
{
RecordIndex = i,
CreditRegistryId = r.CreditRegistryId,
AccountNumber = r.AccountNo,
});

关于linq - LINQ 中的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6014367/

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