Skip to content

Fix missing Edm.Time (TimeSpan) support in OData v2 filter expressions - #57

Merged
joadan merged 1 commit into
masterfrom
copilot/fix-odata-2-edm-time-converter
Jul 1, 2026
Merged

Fix missing Edm.Time (TimeSpan) support in OData v2 filter expressions#57
joadan merged 1 commit into
masterfrom
copilot/fix-odata-2-edm-time-converter

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

TimeSpan properties (mapped from Edm.Time in OData v2) could not be used in LINQ filter expressions — AppendByValueType had no handler for TimeSpan, causing NotSupportedException. No ToODataFilter overload existed for TimeSpan in FilterHelper.

Changes

  • FilterHelper.cs — Added ToODataFilter(TimeSpan, ODataVersion) and nullable overload. Produces time'PT9H18M39S' for v2/v3 and duration'PT9H18M39S' for v4, using XmlConvert.ToString for ISO 8601 duration serialization.
  • FilterExpressionVisitor.cs — Added TimeSpan branch in AppendByValueType (TypeCode.Object), delegating to the new FilterHelper overload.
  • FilterExpressionTests.cs — Added Duration/OptionalDuration (TimeSpan/TimeSpan?) to TestProduct; added #region TimeSpan Tests covering v2/v4 literals, comparison operators, nullable, and inline constants.
  • ODataTimeSpanConverterTests.cs — Added "PT09H18M39S" (the exact server-reported value) as an inline theory case; added OData v2 response round-trip tests for both non-nullable and nullable Edm.Time properties.

Example

// Previously threw NotSupportedException
Expression<Func<MyEntity, bool>> expr = e => e.Duration == new TimeSpan(9, 18, 39);
var filter = visitor.ToFilter(expr, ODataVersion.V2);
// Now produces: (Duration eq time'PT9H18M39S')

var filter4 = visitor.ToFilter(expr, ODataVersion.V4);
// Now produces: (Duration eq duration'PT9H18M39S')

Copilot AI changed the title Add OData v2 Edm.Time / TimeSpan filter support Fix missing Edm.Time (TimeSpan) support in OData v2 filter expressions Jul 1, 2026
Copilot AI requested a review from joadan July 1, 2026 11:14
Copilot finished work on behalf of joadan July 1, 2026 11:14
@joadan
joadan marked this pull request as ready for review July 1, 2026 13:32
@joadan
joadan merged commit 5831d47 into master Jul 1, 2026
1 check passed
@joadan
joadan deleted the copilot/fix-odata-2-edm-time-converter branch July 1, 2026 13:32
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