From 5a1d85f34f015d81d915f6681bbc85d5f74d4ace Mon Sep 17 00:00:00 2001 From: Mohammad Rahhal Date: Fri, 2 Feb 2024 14:18:15 +0100 Subject: [PATCH] Comments --- .../KeysetFilterPredicateStrategy.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/MR.EntityFrameworkCore.KeysetPagination/KeysetFilterPredicateStrategy.cs b/src/MR.EntityFrameworkCore.KeysetPagination/KeysetFilterPredicateStrategy.cs index a5cbeb1..28910e2 100644 --- a/src/MR.EntityFrameworkCore.KeysetPagination/KeysetFilterPredicateStrategy.cs +++ b/src/MR.EntityFrameworkCore.KeysetPagination/KeysetFilterPredicateStrategy.cs @@ -91,6 +91,8 @@ protected static BinaryExpression MakeComparisonExpression( } else { + // We call EnsureAdditionalConversions only when generating comparisons as these conversions + // are unneeded when generating an equality (Expression.Equal). return compare( EnsureAdditionalConversions(memberAccess), EnsureAdditionalConversions(EnsureMatchingType(memberAccess, referenceValue))); @@ -99,11 +101,11 @@ protected static BinaryExpression MakeComparisonExpression( private static Expression EnsureAdditionalConversions(Expression expression) { + // For enums, we need to convert to the underlying type for comparisons to work. if (expression.Type.IsEnum) { - var enumUnderlyingType = Enum.GetUnderlyingType(expression.Type); - - return Expression.Convert(expression, enumUnderlyingType); + var underlyingType = Enum.GetUnderlyingType(expression.Type); + return Expression.Convert(expression, underlyingType); } return expression;