Description
Summary
UpdateDefinition can't handle casts when combined (calling multiple Set).
Driver version: 2.19.0
Repro
using System.Linq.Expressions;
|
using MongoDB.Driver;
|
using MongoDB.Driver.Linq;
|
var mongoUrl = MongoUrl.Create("mongodb://admin:123456@localhost/management_reports?authMechanism=SCRAM-SHA-1;authSource=admin;minPoolSize=1;retryWrites=true"); |
var clientSettings = MongoClientSettings.FromUrl(mongoUrl);
|
clientSettings.LinqProvider = LinqProvider.V3;
|
var client = new MongoClient(clientSettings); |
var db = client.GetDatabase("test"); |
var carCollection = db.GetCollection<Car>("cars"); |
var updateDef = GetUpdateFieldDefinition((t => t.Type, "super-fast"), (t => t.Price, 100m)); |
await carCollection.UpdateManyAsync(t => t.Type == "fast", updateDef); |
Console.ReadKey();
|
static UpdateDefinition<Car> GetUpdateFieldDefinition(params (Expression<Func<Car, object>> fieldSelector, object value)[] fieldsToUpdate) |
{
|
UpdateDefinition<Car> updateDefinition = null; |
foreach (var (fieldSelector, value) in fieldsToUpdate)
|
{
|
updateDefinition = updateDefinition?.Set(fieldSelector, value) ?? Builders<Car>.Update.Set(fieldSelector, value);
|
}
|
return updateDefinition; |
}
|
public class Car |
{
|
public string Type { get; set; } |
public decimal Price { get; set; } |
}
|
Attachments
Issue Links
- duplicates
-
CSHARP-4499 Support Convert calls to a base type in filter translators
-
- Closed
-
- is related to
-
CSHARP-4428 LINQ3 not handling down cast in UpdateDefinitionBuilder Set method
-
- Closed
-