Everything was working okay with the previous version of MongoDb driver version 2.17.1 and now I have upgrade my MongoDb driver to lastest version 2.19.1 and now I get this error: 'Expression not supported: Convert(o.DataStatusID) because conversion to System.Nullable`1[System.Int32] is not supported
Data class:
public byte? DataStatusID {get; set;}
LoadData():
Collection.FindSync<Data>(o => o.DataStatusID == 1)
how to get around this error?
Besides a possible version mismatch between driver and engine (which really should not allow a connection at all in case of any incompatibility IMO), there is the following connection setting that allows you to chose between three different versions of the MongoDb LINQ Provider:
var connectionString = "mongodb://localhost";
var clientSettings = MongoClientSettings.FromConnectionString(connectionString);
clientSettings.LinqProvider = LinqProvider.V3;
var client = new MongoClient(clientSettings);
Recently (2023-10), V2 was still their default. A problem similar to, but not identical with, your observation was solved by setting this to V3. Since then, V3 now appears to be the default (as of driver version 2.19) and V1 is gone for good.
Your mileage may vary, I actually had it both ways around in production: for an expression of the form
lambda.get_Item("field")
towards a MongoDb 7.0 and with the C# Driver version 2.19.2 I had to downgrade to V2 to make it work:
clientSettings.LinqProvider = LinqProvider.V2;
Documentation:
https://mongodb.github.io/mongo-csharp-driver/2.18/reference/driver/crud/linq3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With