我有这个 LINQ 查询。
var sumOfData = fullData.AsEnumerable().GroupBy(x => new { x.transactionId, x.checkId }).
Where(p => (p.Key.checkId == variable.checkId) && (p.Key.transactionId == variable.transactionId))
.Select(y => new
{
checkId = variable.checkId,
transactionId = variable.transactionId,
SumAppliedAmt = y.Sum(z => z.appliedAmount),
SumCheckAmt = y.Sum(x => x.checkAmount)
});
如何访问里面的数据sumOfData
?
我需要做什么才能访问sumOfData.checkId
或sumOfData.transactionId
?我想在不使用 foreach 循环的情况下访问它。对不起,我忘了添加那部分。我已经在使用一个 LINQforeach (var data in fullDataQuery)
并在 foreach 中放置一个 foreach 将是性能密集型 { if (data.invoiceBalance==) }
也可以直接更新到
var fullDataQuery = remitFile.AsEnumerable().Select(
remitInfofullData => new
{
checkId = remitInfofullData.Field<int>("checkId"),
depositId = remitInfofullData.Field<int>("depositId"),
appliedAmount = remitInfofullData.Field<decimal>("appliedAmount"),
checkAmount = remitInfofullData.Field<decimal>("checkAmount"),
invoiceBalance = remitInfofullData.Field<decimal>("invoiceBalance"),
sequenceId = remitInfofullData.Field<int>("sequenceId"),
remittanceId = remitInfofullData.Field<int>("remittanceId"),
fileId = remitInfofullData.Field<int>("fileId"),
transactionId = remitInfofullData.Field<int>("transactionId"),
}).Where(p => (p.checkId == variable.checkId) && (p.transactionId == variable.transactionId)); using var sumOfData = fullData.AsEnumerable().GroupBy(x => new { x.transactionId, x.checkId }).
Where(p => (p.Key.checkId == variable.checkId) && (p.Key.transactionId == variable.transactionId))
.Select(y => new
{
checkId = variable.checkId,
transactionId = variable.transactionId,
SumAppliedAmt = y.Sum(z => z.appliedAmount),
SumCheckAmt = y.Sum(x => x.checkAmount)
}); the sumAppliedAmount value