'EF Core Filtering

I have something that currently looks like this and works in EF Core:

DbContext.Computers.OrderByDirection(state.SortDirection, 
    x => x.Actions.FirstOrDefault(y => y.GetType() == typeof(PingAction) && 
    y.History.Any(z => z.Status == Status.Succeeded && 
    (DateTime.Now - z.WhenExecuted).TotalMinutes < 10)))

However I also need to use the x function elsewhere and don't want to hard code it multiple times. How can I save that function to a variable or something and still allow it to work with the server sided filtering of EF core since of course this will be translated to SQL?

UPDATE

Signatures for OrderByDirection:

public static IOrderedEnumerable<TSource> OrderByDirection<TSource, TKey>(this IEnumerable<TSource> source, SortDirection direction, Func<TSource, TKey> keySelector)
public static IOrderedQueryable<TSource> OrderByDirection<TSource, TKey>(this IQueryable<TSource> source, SortDirection direction, Expression<Func<TSource, TKey>> keySelector)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source