Full featured LINQ support for TimeSpan

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.3
    • Component/s: LINQ
    • None
    • Environment:
      MongoDB.Driver 2.3.0
      .net core (netstandard1.5)
      Mongo 3.2
      Visual Studio 2015
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I want to create an simple aggregation request using linq expression to extract groups and calculate some values.
      It works fine except for property of type TimeSpan.

      collection.Aggregate()
      .Match(x => x.Date >= minimumDate)
      .Group(
      x => x.UserId,
      group => new

      { id = group.Key, Count = group.Count(), Price = group.Sum(x => x.Price), // float : ok Duration = group.Sum(x => x.Duration) // TimeSpan : ko !! }

      );

      The Sum of Duration property for group does not work. There is no Sum extension method that accept a TimeSpan in System.Linq.Enumerable.
      If I change to x => x.Duration.Ticks, the Driver throws an exception with message saying that it does not know translate Ticks.
      I tried to create a Sum extension method accepting a TimeSpan. It compiles but yet fails at runtime because the driver does not recognize this method that is not part of the framework.

      So how to do. I do not want to used aggregate API with BsonDocument. I want to use linq expression as it allow to abstract the data access layer and it is great for unit tests.

            Assignee:
            Robert Stam
            Reporter:
            Frédéric Barrière
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: