Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LINQ: Adds support for Nullable<T>.Value or Nullable<T>.HasValue when using camelCase serialization #2917

Merged
merged 10 commits into from
Jan 3, 2022

Conversation

ssa3512
Copy link
Contributor

@ssa3512 ssa3512 commented Dec 1, 2021

Pull Request Template

Description

Uses the configured serializer settings when checking for the special cases of Nullable<T>.Value and Nullable<T>.HasValue

This allows the use of .HasValue when using camelCase serialization, as it currently translates to ["propName"]["hasValue"] in the resultant query instead of the intended IS_DEFINED("propName")

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Closing issues

Closes #2916

@ssa3512
Copy link
Contributor Author

ssa3512 commented Dec 1, 2021

I could use some assistance with direction on where I should add some unit tests for this. It was looking like perhaps LinqSQLTranslationBaselineTests, LinqTranslationBaselineTests would be the place for this, but I can't figure out how the tests are asserting the correct query output.

@j82w
Copy link
Contributor

j82w commented Dec 2, 2021

@timsander1 or @khdang can you please take a look?

@j82w
Copy link
Contributor

j82w commented Dec 3, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@khdang
Copy link
Member

khdang commented Dec 7, 2021

@ssa3512 you can consider adding unit tests to CosmosItemLinqTests.cs. The LinqSQLTranslationBaselineTests, LinqTranslationBaselineTests tests are also the right place. They are baseline tests which produce xml files as output and they assert by comparing the output files with the existing baseline files in https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline

@ssa3512
Copy link
Contributor Author

ssa3512 commented Dec 14, 2021

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 2917 in repo Azure/azure-cosmos-dotnet-v3

@j82w
Copy link
Contributor

j82w commented Dec 14, 2021

/azp run

@ssa3512
Copy link
Contributor Author

ssa3512 commented Dec 14, 2021

@khdang I added tests to the CosmosItemLinqTests to verify the translation of HasValue to IS_DEFINED. Can you please review?

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ssa3512 ssa3512 requested a review from khdang December 20, 2021 18:48
@j82w
Copy link
Contributor

j82w commented Dec 20, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ssa3512
Copy link
Contributor Author

ssa3512 commented Dec 20, 2021

@j82w can you re-run the "Preview Tests Release" job? The test failure there is not occurring locally, and does not appear to be at all related to my changes.

@@ -69,6 +74,7 @@ public TranslationContext(CosmosLinqSerializerOptions linqSerializerOptions, IDi
{
this.linqSerializerOptions = linqSerializerOptions;
this.parameters = parameters;
this.memberNames = new MemberNames(linqSerializerOptions);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khdang any objections to consolidating these constructors into a single constructor? The first parameterless constructor is currently only called by the second constructor that takes the serializer options and the class is internal so there are no public API concerns. This will ensure that there is no path where memberNames is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and did this in the latest round of changes. Please let me know if you have any issues.

@ssa3512 ssa3512 requested a review from khdang December 23, 2021 18:18
@j82w
Copy link
Contributor

j82w commented Jan 3, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@j82w j82w changed the title Use serializer settings when checking for Nullable<T>.Value or Nullable<T>.HasValue LINQ: Adds support for Nullable<T>.Value or Nullable<T>.HasValue when using camelCase serialization Jan 3, 2022
@j82w j82w enabled auto-merge (squash) January 3, 2022 22:03
@j82w j82w merged commit 5375929 into Azure:master Jan 3, 2022
@ssa3512 ssa3512 deleted the fix-2916 branch January 3, 2022 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linq expression on Nullable<T>.HasValue does not work when using camelCase serialization
4 participants