-
Type: Question
-
Resolution: Works as Designed
-
Priority: Unknown
-
None
-
Affects Version/s: 2.24.0
-
Component/s: LINQ3
-
None
-
Dotnet Drivers
Summary
Issues with LinqProvider.V3
Driver Version: C# driver 2.24.0
How to Reproduce
var connectionString = "mongodb://localhost:27017"; var setting = MongoClientSettings.FromConnectionString(connectionString); setting.LinqProvider = LinqProvider.V3; var mongoClient = new MongoClient(setting); var db = mongoClient.GetDatabase("test"); var coll = db.GetCollection<CallRecord>("calls"); var result = coll.AsQueryable() .Select(p => new {name= p.PhoneNumber,DurationInMinute = Math.Ceiling((float)p.Duration / 60) }); var array = await result.ToListAsync(); foreach (var record in array) { Console.WriteLine($"phone:{record.name},Duration:{record.DurationInMinute}"); } public record CallRecord(string PhoneNumber,int Duration);
As shown in the code, if setting.LinqProvider = LinqProvider.V2 is set, it can run normally. However, if setting.LinqProvider = LinqProvider.V3 is set, the following error occurs:
Unhandled exception. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: Convert(p.Duration, Single) because conversion to System.Single is not supported.
at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ConvertExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, UnaryExpression expression)