C# 在linq查询中使用sharepoint分类法值作为排序参数
我的问题如下:C# 在linq查询中使用sharepoint分类法值作为排序参数,c#,sharepoint-2010,C#,Sharepoint 2010,我的问题如下: 我正在使用对IEnumerable(即我的客户列表)进行排序 按降序排列 我得到上述查询的输出,如下所示 不可数的 之后,我将使用一系列ThenByDescending查询对其进行排序。其中一个查询正在使用类型为“TaxonomyFieldValue”的Sharepoint分类字段 我正在为此使用以下代码: orderedCustomerList = orderedCustomerList.ThenByDescending(o =&
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类型成员
我得到以下错误-对象引用未设置为对象的实例
提前谢谢。任何帮助都将不胜感激。我已经解决了这个问题。我选择回答这个问题,而不是添加评论。 我使用以下方法将custItem类的taxonomyFieldvalue类型成员转换为taxonomyFieldvalue集合:
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));
}
谢谢大家