运算符 && 不能应用于十进制和十进制类型的操作数



我想获取性能和可用时间的最后 5 个值。为了做到这一点,我尝试了多种方法,但不幸的是没有成功。

我试过这个:

var completeTransactions2 = temp4
                        .Where(x => x.GroupidAvai == x.GroupidPerf && x.KeyTimeAvai == x.KeyTimePerf)
                        .GroupBy(x => x.GroupidAvai)
                        .Select(group => group.OrderByDescending(record => (record.KeyTimeAvai) && (record.KeyTimePerf)).Take(5));

但随后我得到一个错误:运算符 && 不能应用于十进制和十进制类型的操作数。

有了这些信息,我尝试了一些东西,但结果只有一个 perfTime 正在获取最后 5 个值并反转它们。可用性只有一个可用时间。这是查询:

var orderedTemp72 = temp4
                        .Where(x => x.GroupidAvai == x.GroupidPerf)
                        .GroupBy(x => new { x.GroupidAvai, x.GroupidPerf })
                        .Select(x => x.OrderByDescending(record => record.KeyTimeAvai)
                        .ThenByDescending(record => record.KeyTimePerf).Take(5).Reverse());

我希望有人能把我放在解决这个问题的正确方向上。如果有问题,请随时提问。

感谢您的阅读。

我认为问题是您的 orderbyDescending 语句。

尝试类似的东西

var completeTransactions2 = temp4
                    .Where(x => x.GroupidAvai == x.GroupidPerf && x.KeyTimeAvai == x.KeyTimePerf)
                    .GroupBy(x => x.GroupidAvai)
                    .Select(group => group.OrderByDescending(record => record.KeyTimeAvai).ThenBy(x => record.KeyTimePerf)).Take(5));

尝试通过执行OrderByDescendingThenByDescending来使用此语法

var completeTransactions2 = temp4
                    .Where(x => x.GroupidAvai == x.GroupidPerf && x.KeyTimeAvai == x.KeyTimePerf)
                    .GroupBy(x => x.GroupidAvai)
                    .Select(gro => gro.OrderByDescending(r => r.KeyTimeAvai).ThenByDescending(r => r.KeyTimePerf).Take(5));

或者OrderByDescendingThenBy

var completeTransactions2 = temp4
                        .Where(x => x.GroupidAvai == x.GroupidPerf && x.KeyTimeAvai == x.KeyTimePerf)
                        .GroupBy(x => x.GroupidAvai)
                        .Select(gro => gro.OrderByDescending(r => r.KeyTimeAvai).ThenBy(r => r.KeyTimePerf).Take(5));

看看这里

如果你想要五个最伟大的KeyTimeAvai或KeyTimePerf

OrderByDescending(x => x.KeyTimeAvai >= x.KeyTimePerf 
                       ? x.KeyTimeAvai 
                       : x.KeyTimePerf).Take(5);

如果你需要五个最伟大的KeyTimeAvai和五个最伟大的KeyTimePerf(所以10个结果),我会做这样的事情。

var groupedTransactions=  temp4
                          .Where(x => x.GroupidAvai == x.GroupidPerf &&
                                      x.KeyTimeAvai == x.KeyTimePerf)
                          .GroupBy(x => x.GroupidAvai);

var greatestByAvai = groupedTransactions
                     .Select(group => group.OrderByDescending(record => record.KeyTimeAvai)
                     .Take(5);
var greatestByPerf = groupedTransactions
                     .Select(group => group.OrderByDescending(record => record.KeyTimePerf)
                     .Take(5);
var allTransactions = greatesByAvai.Concat(greatestByPerf);

谢谢大家的回应/帮助。真的很感激:)有了您的所有答案,我得出了以下可以使用的解决方案。

var completeTransactions = temp
                    .Where(x => x.GroupidAvai == x.GroupidPerf && x.KeyTimeAvai == x.KeyTimePerf)
                    .GroupBy(x => x.GroupidAvai)
                        .Select(group => group.OrderByDescending(record => record.KeyTimeAvai).Reverse().Take(5).OrderByDescending(record => record.KeyTimePerf).Reverse().Take(5));

相关内容

  • 没有找到相关文章

最新更新