diff --git a/EFCore.sln.DotSettings b/EFCore.sln.DotSettings
index f531c36ce1b..e09a00ba6f5 100644
--- a/EFCore.sln.DotSettings
+++ b/EFCore.sln.DotSettings
@@ -328,6 +328,9 @@ The .NET Foundation licenses this file to you under the MIT license.
True
True
True
+ True
+ True
+ True
True
True
True
diff --git a/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs b/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs
index 9c88522fb05..e029d9ad72a 100644
--- a/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs
+++ b/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs
@@ -226,6 +226,15 @@ public override Expression VisitBinaryExpression(BinaryExpressionSyntax binary)
var left = Visit(binary.Left);
var right = Visit(binary.Right);
+ if (Nullable.GetUnderlyingType(left.Type) == right.Type)
+ {
+ right = Convert(right, left.Type);
+ }
+ else if (Nullable.GetUnderlyingType(right.Type) == left.Type)
+ {
+ left = Convert(left, right.Type);
+ }
+
// https://learn.microsoft.com/dotnet/api/Microsoft.CodeAnalysis.CSharp.Syntax.BinaryExpressionSyntax
return binary.Kind() switch
{
@@ -406,7 +415,8 @@ public override Expression VisitIdentifierName(IdentifierNameSyntax identifierNa
new FakeFieldInfo(
typeof(FakeClosureFrameClass),
ResolveType(localSymbol.Type),
- localSymbol.Name)));
+ localSymbol.Name,
+ localSymbol.NullableAnnotation is NullableAnnotation.NotAnnotated)));
}
throw new InvalidOperationException(
@@ -1123,6 +1133,11 @@ private Type ResolveType(ITypeSymbol typeSymbol, Dictionary? gener
Type GetClrType(INamedTypeSymbol symbol)
{
+ if (symbol.SpecialType == SpecialType.System_Nullable_T)
+ {
+ return typeof(Nullable<>);
+ }
+
var name = symbol.ContainingType is null
? typeSymbol.ToDisplayString(QualifiedTypeNameSymbolDisplayFormat)
: typeSymbol.Name;
@@ -1205,8 +1220,15 @@ public int GetHashCode(T[] obj)
[CompilerGenerated]
private sealed class FakeClosureFrameClass;
- private sealed class FakeFieldInfo(Type declaringType, Type fieldType, string name) : FieldInfo
+ private sealed class FakeFieldInfo(
+ Type declaringType,
+ Type fieldType,
+ string name,
+ bool isNonNullableReferenceType)
+ : FieldInfo, IParameterNullabilityInfo
{
+ public bool IsNonNullableReferenceType { get; } = isNonNullableReferenceType;
+
public override object[] GetCustomAttributes(bool inherit)
=> Array.Empty