Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown discriminator value C# Mongo

Tags:

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;     } } 
like image 856
CurlyFro Avatar asked Mar 13 '15 19:03

CurlyFro


1 Answers

Got it. I just needed to add a classmap:

BsonClassMap.RegisterClassMap<ProductPropertyDefinition>(); 
like image 161
CurlyFro Avatar answered Sep 20 '22 18:09

CurlyFro