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

时间:2016-07-15 08:10:24

标签: c# linq lambda xamarin.android

我想获得性能和可用时间的最后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个值并反转它们。可用性只有一个avaitime。这是查询:

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());

我希望有人可以帮我解决这个问题。如果有疑问,请不要犹豫。

感谢您的阅读。

4 个答案:

答案 0 :(得分:1)

我认为问题是你的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));

答案 1 :(得分:1)

通过执行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));

看看Here

答案 2 :(得分:1)

如果你想要五个最伟大的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);

答案 3 :(得分:1)

谢谢大家回复/帮助我。非常感谢 :) 通过所有答案,我得出了以下可以使用的解决方案。

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));