diff --git a/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs b/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs index 83e36f8282c..c419468fe65 100644 --- a/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs @@ -252,7 +252,8 @@ public virtual void ClearOrdering() public virtual void ApplyPredicate([NotNull] SqlExpression expression) { if (expression is SqlConstantExpression sqlConstant - && (bool)sqlConstant.Value) + && sqlConstant.Value is bool boolValue + && boolValue) { return; } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 9f88bf795c2..2db70828552 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -230,7 +230,8 @@ public void ApplyPredicate([NotNull] SqlExpression expression) Check.NotNull(expression, nameof(expression)); if (expression is SqlConstantExpression sqlConstant - && (bool)sqlConstant.Value) + && sqlConstant.Value is bool boolValue + && boolValue) { return; }