gpt4 book ai didi

c# - 获取对象计数总和

转载 作者:行者123 更新时间:2023-11-30 23:06:24 29 4
gpt4 key购买 nike

我有一个像这样的 Lambda 表达式:

model =
db.MyTable.Where(
x => x.deleted == false && x.MyDate.Month == monthInt && x.MyDate.Year == yearInt)
.GroupBy(x => x.codeAC.ACatagory.Text)
.Select(y => new MainAssignmentReportVM()
{
Title = y.Key,
Children = y.Select(z => new AssignmentReportVM()
{
Assignment = z.codeAC.text,
Location = z.codeLocation.Location,
Count =
y.Count(
t =>
t.codeAC.text == z.codeAC.text &&
t.codeLocation.Location == z.codeLocation.Location),
EachFlightTotal = y.Where(s => s.codeAC.text == z.codeAC.text && s.codeLocation.Location == z.codeLocation.Location).Sum(s => s.Flight.Value),
TotalFlightCombined = y.Sum(x => x.Flight.Value),
// AssignmentTotalCount -- This is where I need help
}).Distinct()
});

我已经在上面的代码中评论了我需要帮助的地方。 AssignmentTotalCount 应该是 Count 的总和。我如何在这个 lambda 表达式中做到这一点?

我正在考虑将 AssignmentTotalCount 设置为只读属性并将其设置在类中,因为它不会被编辑或任何其他内容......但我不知道如何在类中进行设置。

感谢任何帮助。

最佳答案

通过将 AssignmentTotalCount 放在您放置的位置,Count 的总和将始终与 Count 相同。

它必须被放置在更高一层,作为 TitleChildren 的兄弟(所以类 MainAssignmentReportVM 的属性而不是类AssignmentReportVM)。然后您应该能够对 Count 求和。

关于c# - 获取对象计数总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48230490/

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