The following code fails in Linq V3 but works if I cahnge to LINQ v2:
var connectionString = "mongodb://localhost/"; var settings = MongoClientSettings.FromConnectionString(connectionString); settings.LinqProvider = MongoDB.Driver.Linq.LinqProvider.V3; var client = new MongoClient(settings); var database = client.GetDatabase("testdb"); var collection = database.GetCollection<IMyInterface>("xx_test_collection"); var filter = Builders<IMyInterface>.Filter.Eq(x=>((MyClass)x).TestValue, 42); var findFluent = collection.Find(filter); Console.WriteLine(findFluent.ToString());
Classes and interfaces are very basic and as follows:
public interface IMyInterface { } public class MyClass : IMyInterface { public int TestValue { get; set;} }
When LinqProvider is set to V2 it correctly outputs
find({ "TestValue" : 42 })
If I run the code with the V3 provider I get:
Expression not supported: Convert(x)
My assumption is that the issue lies in the code in ConvertExpressionToFilterFieldTranslator where IsConvertToDerivedType feels like it should return true but because it checks for IsSubclassOf rather than IsAssignableFrom it decides that it can't convert.
Also I am aware that I can rewrite this using OfType but I figure if it works in V2 then it should work in V3 too.