-
Notifications
You must be signed in to change notification settings - Fork 494
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
Query: Fixes Equals method on SqlParameter class #2044
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the required format: "[Internal] Category: (Adds|Fixes|Refactors) Description"
Examples:
Diagnostics: Adds GetElapsedClientLatency to CosmosDiagnostics
PartitionKey: Fixes null reference when using default(PartitionKey)
[v4] Client Encryption: Refactors code to external project
[Internal] Query: Adds code generator for CosmosNumbers for easy additions in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the required format: "[Internal] Category: (Adds|Fixes|Refactors) Description"
Examples:
Diagnostics: Adds GetElapsedClientLatency to CosmosDiagnostics
PartitionKey: Fixes null reference when using default(PartitionKey)
[v4] Client Encryption: Refactors code to external project
[Internal] Query: Adds code generator for CosmosNumbers for easy additions in the future.
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SqlParameterEqualityTests.cs
Show resolved
Hide resolved
@@ -79,7 +79,8 @@ public bool Equals(SqlParameter other) | |||
return true; | |||
} | |||
|
|||
return this.Name == other.Name && this.Value == other.Value; | |||
return this.Name == other.Name | |||
&& other.Value == null ? this.Value == null : other.Value.Equals(this.Value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't work for arrays and object, since they don't override .Eqauls() and we need to do a deep equality here.
The long term / proper solution is to compare the JSONs for equivalency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but please track the array and object cases.
Closing due to in-activity, pease feel free to re-open. |
Pull Request Template
Description
SqlParameterEquality relies on == operator on Name and Value. While this is okay for Name since that is explictly typed as a string, it fails for value since that is typed as an object. For an object (even when it is a string) == falls to Object.ReferenceEquals, while the right thing to do is call the Equals method.
The unit tests were passing because they use literal strings, which have the same reference in testing. I have also changed the unit tests.
Type of change
Please delete options that are not relevant.
Closing issues