0

我的问题如下:

  1. 我正在使用 OrderByDescending 对 IEnumerable<custItem> 即我的客户列表进行排序。
  2. 我将上述查询的输出作为 IOrderedEnumerable<custItem>。
  3. 之后,我使用一系列 ThenByDescending 查询对其进行排序。查询之一是使用“TaxonomyFieldValue”类型的 Sharepoint 分类字段。

我正在使用以下代码:

                        orderedCustomerList = orderedCustomerList.ThenByDescending(o =>
                    {
                        if (o.Country != null && currentCustomerItem.Country != null)
                        {
                            if (o.Country.Label == currentCustomerItem.Country.Label)
                            {
                                return o;
                            }
                            return null;
                        }
                        return null;
                    });

有时我会遇到以下错误 - 至少一个对象必须实现 Icomparable。

有时它会起作用。

我还尝试使用以下代码:

orderedCustomerList = orderedCustomerList.ThenByDescending(o => o.Country.ToString().Contains(currentCustomerItem.Country.Label));

Country 是 custItem 类的 TaxonomyFieldValue 类型成员。

我收到以下错误 - 对象引用未设置为对象的实例。

提前致谢。任何帮助将不胜感激。

4

1 回答 1

0

我已经解决了这个问题。我选择回答这个问题而不是添加评论。我使用以下方法将 custItem 类的这个 taxonomyFieldvalue 类型成员转换为 taxonomyFieldvalueCollection:

private TaxonomyFieldValueCollection TaxonomyFieldToCollection(object item)
    {
        if (item != null)
        {
            TaxonomyFieldValue temp = item as TaxonomyFieldValue;
            TaxonomyFieldValueCollection tempCol = new TaxonomyFieldValueCollection(temp.ValidatedString);
            return tempCol;
        }
        else
        {
            TaxonomyFieldValueCollection tempCol = new TaxonomyFieldValueCollection(string.Empty);
            tempCol.Clear();
            return tempCol;
        }
    }

然后我使用以下命令进行排序:

foreach (TaxonomyFieldValue value in currentCustomerItem.Country)
{
     orderedCustomerList = orderedCustomerList.ThenByDescending(o => o.Country.ToString().Contains(value.Label));
}

感谢大家。

于 2013-08-21T03:55:23.350 回答