我正在尝试按“V0003”、“4323Fw”类型对数据进行排序,但比较器出现错误,出了什么问题,如何在 IQueryable 中排序?
我的比较器:
public class NumericStringComparer : IComparer<string>
{
public int Compare(string s1, string s2)
{
const int S1GreaterThanS2 = 1;
const int S2GreaterThanS1 = -1;
const int S2EqualsS1 = 0;
var isS1Numeric = IsNumeric(s1);
var isS2Numeric = IsNumeric(s2);
if (isS1Numeric && isS2Numeric)
{
var firstNum = Convert.ToInt64(s1);
var secondNum = Convert.ToInt64(s2);
if (firstNum > secondNum)
{
return S1GreaterThanS2;
}
if (firstNum < secondNum)
{
return S2GreaterThanS1;
}
return S2EqualsS1;
}
if (isS1Numeric)
{
return S2GreaterThanS1;
}
if (isS2Numeric)
{
return S1GreaterThanS2;
}
return string.Compare(s1, s2, true, CultureInfo.InvariantCulture);
static bool IsNumeric(string value)
{
return long.TryParse(value, out _);
}
}
}
我的排序:
query.OrderBy(bdc => bdc.Code, comparer), // query is IQueryable<MyClass>
错误:
StagesBudgetCycle == (int)(short)__StagesBudgetCycle_0))))\r\n .OrderBy(\r\n keySelector: bdc => bdc.Code, \r\n comparer: __p_1)""无法翻译。以可以翻译的形式重写查询”、“或通过插入对“AsEnumerable”、“AsAsyncEnumerable”、“ToList”、“或”“ToListAsync”的调用显式切换到客户端评估。有关详细信息,请参阅 https"://go.microsoft.com/fwlink/?linkid=2101038。AsAsyncEnumerable"、"ToList"、"或""ToListAsync""。有关详细信息,请参阅 https"://go.microsoft.com/fwlink/?linkid=2101038。AsAsyncEnumerable"、"ToList"、"或""ToListAsync""。有关详细信息,请参阅 https"://go.microsoft.com/fwlink/?linkid=2101038。