LINQ3 Provider Doesn't Support Some Casts Properly

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: 3.4.0
    • Component/s: LINQ3
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      I'm upgrading from version 2.x to 3.x of the C# driver where the old LINQ2 provider has been deprecated and now I must switch to the new provider. It seems the newer provider was made more strict about handling casts (both implicit and explicit) in LINQ expressions. It also seems that there are some edge cases where this was taken too far. I have an aggregate group query that worked fine in LINQ2 and is now throwing: 

      MongoDB.Driver.Linq.ExpressionNotSupportedException : Expression not supported: ConvertChecked(x.Count(), Int64).

      Here's the code:

      collection.Aggregate().Group<MyType, string?, MyResult>(
          x => x.MyField,
          x => new MyResult { Name = x.Key, Count = x.Count() });

      The problem here is that the Count property of MyResult is defined as a long (Int64), but the return type of the linq Count() method is int (Int32). This results in an implicit cast in the expression tree that the linq provider is choking on. However, we really need to keep the type of the count property in our model class as a long (Int64). I don't really know what type mongo is doing with the $count this gets translated as, but I would almost assume its a 64 rather than 32 bit integer.

            Assignee:
            Robert Stam
            Reporter:
            David Milligan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: