Skip to content

EF-459: Throw for date parts and calendar adds over a Local-kind DateTime property - #378

Open
ajcvickers wants to merge 2 commits into
mongodb:mainfrom
ajcvickers:EF-459
Open

ajcvickers wants to merge 2 commits into
mongodb:mainfrom
ajcvickers:EF-459

Conversation

@ajcvickers

Copy link
Copy Markdown
Collaborator

The driver's LINQ renders date parts and AddYears/AddMonths/AddDays without a timezone, so over a HasDateTimeKind(Local) property the server evaluated them on the stored UTC instant while the entity materializes as local time, silently returning wrong values or rows. Fail loudly until the driver can render a timezone.

Also declines the same members over a DateTime member of a projected tuple or record, whose source property cannot be determined. Resolves shared owned types by navigation so a Utc-kind owner is not declined.

…Time property

The driver's LINQ renders date parts and AddYears/AddMonths/AddDays without a
timezone, so over a HasDateTimeKind(Local) property the server evaluated them on
the stored UTC instant while the entity materializes as local time, silently
returning wrong values or rows. Fail loudly until the driver can render a timezone.

Also declines the same members over a DateTime member of a projected tuple or
record, whose source property cannot be determined. Resolves shared owned types
by navigation so a Utc-kind owner is not declined.
@ajcvickers

Copy link
Copy Markdown
Collaborator Author

Note that this does not fix EF-459, it just makes it throw rather than returning wrong data on the driver path. The only reasonable way to fix this is in the driver LINQ itself.

@ajcvickers
ajcvickers marked this pull request as ready for review October 13, 2026 17:09
@ajcvickers
ajcvickers requested a review from a team as a code owner October 13, 2026 17:09
@ajcvickers
ajcvickers requested review from adelinowona and damieng and removed request for adelinowona October 13, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Duration additions remain incorrect across DST, and some user-defined record namespaces bypass the projection guard.

2 open findings
What changed in this PR

Prevents incorrect server-side date operations on Local-kind DateTime properties.

Changes:

  • Adds translation guards for date parts and calendar additions.
  • Adds functional coverage for properties, projections, and bulk updates.
  • Documents the breaking behavior change.
File Description
MongoEFToLinqTranslatingExpressionVisitor.cs Detects unsafe Local-kind operations.
LocalKindDateTimeTests.cs Adds regression coverage.
BREAKING-CHANGES.md Documents behavior and mitigations.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ntify framework types by assembly

AddHours/AddMinutes/AddSeconds/AddMilliseconds over a Local-kind DateTime property
now throw like AddDays, since the server adds an absolute UTC duration which diverges
from local-time arithmetic across a DST transition.

IsProjectionContainer identified framework types by a "System" namespace prefix, so a
user type in e.g. Systems.Domain bypassed the unresolved-source guard. It now checks
the declaring assembly and ITuple.

This branch has not been deployed

No deployments
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.

2 participants