Skip to content

Commit

Permalink
Optimize BuildContainsExpression method performance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sfmskywalker committed Feb 7, 2024
1 parent e64a2ea commit decb5d8
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit decb5d8

Please sign in to comment.