'MongoDb - Unable to determine the serialization information
I want to update a property that exists on a class that inherits from the ISettingWidgets interface.
When I run the code below, I get the error: System.InvalidOperationException: Unable to determine the serialization information for o => Convert(o.Settings.get_Item(-1).Data, ISettingWidgets).Widgets.
How can I update the widgets property?
public static async Task SaveWidgets(Guid userId, string settingName, List<IWidget> widgets)
{
var db = GetCollection();
var addDef = Builders<UserInfo>.Update.Set(o => ((ISettingWidgets)o.Settings[-1].Data).Widgets, widgets);
await coll.UpdateOneAsync(p => p.UserId == userId && p.Settings[-1].Name == settingName, addDef);
}
-----------------
public class UserInfo {
public List<Setting> Settings { get; set; }
}
public class Setting
{
public string Name { get; set; }
public ISettingItem Data { get; set; }
}
public class HomePageSettings : ISettingItem, ISettingWidgets
{
public List<IWidget> Widgets { get; set; }
[BsonDefaultValue(9)]
public int ContentWidth { get; set; }
}
public class ProfilePageSettings : ISettingItem
{
[BsonDefaultValue(9)]
public int ContentWidth { get; set; }
}
public interface ISettingWidgets
{
public List<IWidget> Widgets { get; set; }
}
public interface ISettingItem
{
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
