From decb5d898ca4e5e0cbebb04972e79de35553e333 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 8 Feb 2024 00:04:45 +0100 Subject: [PATCH] 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. --- .../Extensions/ExpressionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Elsa.EntityFrameworkCore.Common/Extensions/ExpressionExtensions.cs b/src/modules/Elsa.EntityFrameworkCore.Common/Extensions/ExpressionExtensions.cs index d05f80980..d58a320a4 100644 --- a/src/modules/Elsa.EntityFrameworkCore.Common/Extensions/ExpressionExtensions.cs +++ b/src/modules/Elsa.EntityFrameworkCore.Common/Extensions/ExpressionExtensions.cs @@ -19,7 +19,7 @@ public static class ExpressionExtensions public static Expression> BuildContainsExpression(this Expression> keySelector, IEnumerable 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));