Optimize BuildContainsExpression method performance

Converted the result of the Select() operation to a list, within the BuildContainsExpression method. This prevents multiple enumerations of the 'entities' variable, improving the performance of the method by reducing the number of iterations.
This commit is contained in:
Sipke Schoorstra 2024-02-08 00:04:45 +01:00
parent e64a2eaa17
commit decb5d898c

View file

@ -19,7 +19,7 @@ public static class ExpressionExtensions
public static Expression<Func<TEntity, bool>> BuildContainsExpression<TEntity>(this Expression<Func<TEntity, string>> keySelector, IEnumerable<TEntity> entities) where TEntity : class
{
var compiledKeySelector = keySelector.Compile();
var list = entities.Select(compiledKeySelector);
var list = entities.Select(compiledKeySelector).ToList();
var property = keySelector.GetProperty()!;
var param = Expression.Parameter(typeof(TEntity));