Summary
We recently updated the NuGet package to the latest version (2.20.0) and noticed that one query doesn't work anymore. After some investigation I read that LINQ3 is now enabled by default. When I change the configuration to use LINQ2, the query works fine.
How to Reproduce
This is the query that works fine with LINQ2:
public async Task<IList<Activity>> GetActivitiesAsync<TActivityObject, TId>(TId objectId, CancellationToken cancellationToken = default) where TActivityObject : ActivityObject<TId> where TId : notnull, IEquatable<TId>, new() { return await _client.ActivityCollection .Find(x => x.Object != null && x.Object.GetType() == typeof(TActivityObject) && ((TActivityObject)x.Object).Id.Equals(objectId)) .SortByDescending(x => x.CreatedAt) .ToListAsync(cancellationToken); }
With LINQ3 we get this exception:
MongoDB.Driver.Linq.ExpressionNotSupportedException : Expression not supported: x.Object.GetType()
I tried to use the "is" operator instead, but it also works only with LINQ2. With LINQ3 I get this exception:
System.Reflection.AmbiguousMatchException : Ambiguous match found.
- is duplicated by
-
CSHARP-2080 Cannot translate simple expression: InvalidOperationException
- Closed