fix(adonet): normalize integer reads - #11283
Conversation
Convert provider-returned values to Int32 with invariant culture for required and nullable reads. Preserve database-null handling and missing-field context, and cover exact values, range boundaries, culture, and conversion exceptions. Extract the independent numeric-conversion fix and its focused test class from the preserved advanced-reminder proposal, with additional regression coverage and helper documentation. Co-authored-by: ksemenenko <mail@ksemenenko.com> Source-Commit: 0c579af Source-Pull-Request: dotnet#9903 Source-Head: ef0f357 Source-Base: 558213b
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation preserves existing exception and null semantics and is comprehensively regression-tested.
Review effort: Lite
Findings: None
What changed in this PR
Normalizes ADO.NET integer reads across provider-specific numeric types using invariant conversion while preserving null and missing-field behavior.
Changes:
- Updated required and nullable
GetInt32helpers. - Added comprehensive provider-independent regression tests.
| File | Description |
|---|---|
src/AdoNet/Shared/Storage/DbExtensions.cs |
Applies invariant numeric conversion. |
test/Extensions/Orleans.AdoNet.Tests/StorageTests/DbExtensionsInt32ConversionTests.cs |
Covers conversions, boundaries, errors, culture, and nulls. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code coverage
Report-only conclusion: improved. The current-main baseline is commit Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities. The comparison remains report-only while normal line and branch variance is calibrated. Coverage details |
Problem
ADO.NET providers can return integer-valued columns as
byte,short,long, ordecimal. The shared named-columnGetInt32helper delegates to the provider's typed getter, which can reject these representations. Nullable integer conversion also depends on the ambient culture.Solution
Convert the provider-returned value with
Convert.ToInt32(value, CultureInfo.InvariantCulture)in both integer helpers. This gives required and nullable reads consistent numeric conversion and overflow behavior while preserving nullableDBNullhandling and missing-field exception context.The change is scoped to the existing internal
DbExtensionsimplementation, its XML summaries, and one provider-independent regression test class. The tests cover exact numeric values, range boundaries, invariant culture, database nulls, invalid conversions, and missing-field context. The public API remains unchanged.Attribution
Extracted from @KSemenenko's #9903, specifically commit
0c579afaa1a6ff8aefecf7b8be06cb5ef790f7ff, with additional focused regression coverage. Preserved source head:ef0f35790de3f6730215319964ad2abdb6605e50; source integration base:558213beed6bf2aecbec59d2d3458810e689912e.This independent fix is based directly on
mainat11333532a501f73c7bc824e07dc3693aa93c3b0a. #9903 remains the preserved source and attribution reference.Microsoft Reviewers: Open in CodeFlow