Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4415

DateTime.Year throws an exception for IQueryable<DateTime>

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.19.0
    • Affects Version/s: 2.18.0
    • Component/s: LINQ3
    • None

      Summary

      Attempting to access a member of a DateTime type (Year, Month, Day, etc) fails with exception: 

      System.NotSupportedException: 'Serializer for System.DateTime must implement IBsonDocumentSerializer to be used with LINQ.'

      thrown from MemberExpressionToAggregationTranslator.Translate.

      I stepped through and found that within MemberExpressionToAggregationExpressionTranslator.TryTranslateDateTimeProperty the 'container.Expression.Type' value is the type of '.Year', not the parent DateTime and as such fails the type check. The 'container.Expression.Expression.Type' is DateTime however so maybe it's just looking at the wrong expression.

      This access worked in V2 so I assume DateTime component access is still intended.

      How to Reproduce

      With an IQueryable<DateTime> attempt to access '.Year'

      Additional Background

      I've included a screen cap of the locals within the TryTranslateDateTimeProperty __ 

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            alistair.steele@trapdoorlabs.uk Alistair Steele
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: