我可以将我的课程保存到mongo,但是我在反序列化时遇到错误。
我收到错误:
' MongoDB.Bson.BsonSerializationException:未知的鉴别器值' ProductPropertyDefinition'。'
我需要帮助。如何告诉mongo正确反序列化?
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;
}
}
答案 0 :(得分:36)
知道了。我只需要添加一个类映射:
BsonClassMap.RegisterClassMap<ProductPropertyDefinition>();