本文介绍了至少有一个对象必须实现icomparable。 LINQ C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我有一个List,我正在申请GroupBy,Orderby&然后使用LINQ-C#。



当我更改requestDate和备注时我得到以下错误。



Dear All,

I have a List and i'm appling GroupBy, Orderby & ThenBy using LINQ-C#.

When i change the requestDate and remarks i'm getting the following erro.

At least one object must implement IComparable.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: At least one object must implement IComparable.





什么我试过了:





What I have tried:

IEnumerable<CandidateRefundVoucherInfo> requestVouchers = CandidateRefundVoucherController.Instance.GetByCenterID(16);

            if (requestVouchers.Count() > 0)
            {
                var CandidateRefundVouchers = requestVouchers.
                    Select(items => new
                    {
                        CertificateID = items.Certificate.ID,
                        items.Certificate.Code,
                        items.Certificate.NameEN,
                        items.Certificate.NameAR,
                        items.Remarks,
                        items.RequestDate,
                        items.NumberOfRefundVoucherRequest,
                        items.StatusType,
                        UpdatedByUser = items.UpdatedByUser.NameEN
                    }).
                    GroupBy(i => new
                    {
                        i.CertificateID,
                        i.Code,
                        i.NameEN,
                        i.NameAR,
                        i.Remarks,
                        i.RequestDate,
                        i.NumberOfRefundVoucherRequest,
                        i.StatusType,
                        i.UpdatedByUser
                    })
                        .OrderByDescending(d => new { d.Key.RequestDate })
                        .ThenBy(l => new { l.Key.Remarks })
                        .Select(item => new
                        {
                            ID = item.Key.CertificateID,
                            Code = item.Key.Code,
                            NameEN = item.Key.NameEN,
                            NameAR = item.Key.NameAR,
                            RequestedVouchers = item.Sum(items => items.NumberOfRefundVoucherRequest),
                            Status = item.Key.StatusType,
                            RequestedDate = item.Key.RequestDate.ToString("dddd, dd MMMM yyyy"),
                            Remarks = item.Key.Remarks,
                            UpdatedBy = item.Key.UpdatedByUser,
                            BindLink = BindCode(item.Key.CertificateID, item.Key.Code)
                        });

                rptCandidateRefundVouchers.DataSource = CandidateRefundVouchers;
                rptCandidateRefundVouchers.DataBind();







任何人都可以帮助我。





谢谢




Can anyone please help me.


Thanks

推荐答案


IEnumerable<CandidateRefundVoucherInfo> candidateRefundVoucherList = requestVouchers;
                var refundVouchers = candidateRefundVoucherList.OrderByDescending(d => d.RequestDate).
                    GroupBy(r => r.RequestDate).Select(item => new {
                    ID = item.First().Certificate.ID,
                    Code = item.First().Certificate.Code,
                    NameEN = item.First().Certificate.NameEN,
                    NameAR = item.First().Certificate.NameAR,
                    RequestedVouchers = item.Sum(items => items.NumberOfRefundVoucherRequest),
                    Status = item.First().StatusType,
                    RequestedDate = item.First().RequestDate.ToString("dddd, dd MMMM yyyy"),
                    Remarks = item.First().Remarks,
                    UpdatedBy = item.First().UpdatedByUser.NameEN,
                    BindLink = BindCode(item.First().Certificate.ID, item.First().Certificate.Code, item.First().RequestDate.ToShortDateString())
                });

                rptCandidateRefundVouchers.DataSource = refundVouchers;
                rptCandidateRefundVouchers.DataBind();


这篇关于至少有一个对象必须实现icomparable。 LINQ C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 03:51