static OrderBySetting FindProperties(IEdmEntityType entity) { var propertyNames = entity.Key().Any() switch { true => entity.Key().Select(k => k.Name), false => entity.StructuralProperties() .Where(p => p.Type.IsPrimitive() && !p.Type.IsStream()) .Select(p => p.Name) .OrderBy(n => n) .Take(1) }; var orderBySettings = new OrderBySetting(); propertyNames.Aggregate(orderBySettings, (settings, name) => { if (settings.Name is null) { settings.Name = name; return(settings); } settings.ThenBy = new() { Name = name }; return(settings.ThenBy); }); return(orderBySettings.Name is null ? null : orderBySettings); } } }
private static Expression GetDefaultOrderByCall(this Expression expression, OrderBySetting settings) { return(settings.ThenBy is null ? GetMethodCall() : GetMethodCall().GetDefaultThenByCall(settings.ThenBy)); Expression GetMethodCall() => expression.GetOrderByCall(settings.Name, nameof(Queryable.OrderBy)); }