Резюме для программиста
Я проверял не на доступе к БД, а просто на коллекции, созданной тут же в коде:
class Program { static void Main(string[] args) { List<A> list = new List<A>() { new A() {B=1, C=9}, new A() {B=2, C=8}, new A() {B=3, C=7}, }; list .AsQueryable() // even without this you get the same exception .OrderBy(o => new { o.B, o.C }) .ToList() .ForEach(o => Console.WriteLine($"{o.B} {o.C}")); } public class A { public int B { get; set; } public int C { get; set; } } }
Вот такое исключение
System.InvalidOperationException
HResult=0x80131509
Message=Failed to compare two elements in the array.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource, Exception e)
at System.Collections.Generic.ArraySortHelper`1.Sort(Span`1 keys, Comparison`1 comparer)
at System.MemoryExtensions.Sort[T](Span`1 span, Comparison`1 comparison)
at System.Linq.EnumerableSorter`2.QuickSort(Int32[] keys, Int32 lo, Int32 hi)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.d__17.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at ConsoleApp1.Program.Main(String[] args) in C:\Users\alexsmith\OneDrive\Desktop\ConsoleApp1\ConsoleApp1\Program.cs:line 21
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
ArgumentException: At least one object must implement IComparable.
Дотнет 5.
Может, у вас какая-то расширяющая либа подключена? Подобную запись видел только в том же DLINQ, но там через строку выражение сортировка задаётся.