private void AddSort(LambdaExpression lambda, bool isStarting, bool ascending) { var body = lambda.Body as MemberExpression; if (body == null) { throw new NotSupportedException($"The expression {lambda} cannot be used in an Order clause"); } if (isStarting) { if (OptionalSortDescriptorBuilder == null) { OptionalSortDescriptorBuilder = _realm.CreateSortDescriptorForTable(_metadata); } else { var badCall = ascending ? "ThenBy" : "ThenByDescending"; throw new NotSupportedException($"You can only use one OrderBy or OrderByDescending clause, subsequent sort conditions should be {badCall}"); } } var sortColName = body.Member.Name; OptionalSortDescriptorBuilder.AddClause(sortColName, ascending); }