I am able to save my class to mongo but I am getting an error deserializing it.
I am getting an error:
'MongoDB.Bson.BsonSerializationException : Unknown discriminator value 'ProductPropertyDefinition'.'
I need help. How to tell mongo to deserialize this correctly?
public class Product { [BsonId] [BsonRepresentation(BsonType.ObjectId)] public string Id { get; set; } public ProductPropertyDefinitionCollection ProductProperties { get; set; } } public class ProductPropertyDefinitionCollection : CollectionBase { public ProductPropertyDefinition this[int index] { get { return (ProductPropertyDefinition)List[index]; } set { List[index] = value; } } public ProductPropertyDefinition this[string name] { get { return GetByName(name); } } public int Add(ProductPropertyDefinition value) { return List.Add(value); } public void Remove(ProductPropertyDefinition value) { List.Remove(value); } public bool Contains(ProductPropertyDefinition value) { return List.Contains(value); } private ProductPropertyDefinition GetByName(string propertyName) { ProductPropertyDefinition profileItem = null; foreach (ProductPropertyDefinition profileProperty in InnerList) { if (profileProperty.PropertyName == propertyName) { profileItem = profileProperty; } } return profileItem; } }
Got it. I just needed to add a classmap:
BsonClassMap.RegisterClassMap<ProductPropertyDefinition>();
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