With the recent update to 10gen c# driver for mongodb I want to update my code so it use the strongly typed version.
My previous call was :
var update2 = new UpdateBuilder();
var index = album.Ratings.IndexOf(rating);
update2.Set("Ratings." + index + ".Number", number);
update2.Set("Rating", album.Rating);
_session.Db().GetCollection<Album>("Album")
.Update(Query<Album>.Where(x => x.Id == objId), update2); //this line is working
The new call would be :
update.Set(x => x.Ratings[index].Number, number);
//update2.Set("Ratings." + index + ".Number", number); previous call
But I get this exception :
Unable to determine the serialization information for the expression: (Album x) => x.Ratings.get_Item(WebApp.Areas.API.Controllers.RatingController+<>c__DisplayClass5.index).Number.
Is there any way I can update an item inside a List?
Interesting problem. This works when using a constant like below:
var update = Update<Album>.Set(x => x.Ratings[0].Number, 10);
However, this apparently breaks when you use a variable, like you have done with index. This is definitely a bug. I have created a Jira issue for it here: https://jira.mongodb.org/browse/CSHARP-598.
This is most likely due to us not partially evaluating the expression before processing it.
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