From 4d9b7bd9848ddde59a8aea50e2dff4c25045f83d Mon Sep 17 00:00:00 2001
From: Maya Painter <130110800+Maya-Painter@users.noreply.github.com>
Date: Fri, 19 Jan 2024 10:23:15 -0800
Subject: [PATCH] Query: Fixes LINQ Translation of SqlNullLiteral Values
(#4260)
* initial commit
* moar tests
* test fix
* more test
---
.../src/Linq/ExpressionToSQL.cs | 3 +-
...seline.TestMemberInitializerDataMember.xml | 222 +++++++++++++++++-
...emberInitializerDotNetCustomSerializer.xml | 100 +++++++-
...seline.TestMemberInitializerNewtonsoft.xml | 222 +++++++++++++++++-
...TranslationWithCustomSerializerBaseline.cs | 38 ++-
5 files changed, 567 insertions(+), 18 deletions(-)
diff --git a/Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs b/Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
index 6be1e82e9c..ad9d02cab4 100644
--- a/Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
+++ b/Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
@@ -495,7 +495,8 @@ private static SqlScalarExpression ApplyCustomConverters(Expression left, SqlLit
memberExpression = left as MemberExpression;
}
- if (memberExpression != null)
+ if (memberExpression != null &&
+ right.Literal is not SqlNullLiteral)
{
Type memberType = memberExpression.Type;
if (memberType.IsNullable())
diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDataMember.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDataMember.xml
index 6734a125fa..215d593da2 100644
--- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDataMember.xml
+++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDataMember.xml
@@ -29,7 +29,7 @@ WHERE (root["numericFieldDataMember"] = 1)]]>
+WHERE (root = {"NumericFieldDataMember": 1, "StringFieldDataMember": "1", "id": null, "Pk": null, "DateTimeFieldDataMember": null, "DataTypeFieldDataMember": null})]]>