score:6

Accepted answer

did you try set AllowTruncation=true for your properities in City class?

public class City
{
    [BsonId]
    [BsonRepresentation(BsonType.Int, AllowTruncation=true)]
    public string id { get; set; }
    [BsonRepresentation(BsonType.Int, AllowTruncation=true)]
    public int value { get; set; }        
}

How do I set the serialization options for the geo values using the official 10gen C# driver?

score:7

You typically don't want your model to know or care how it's being stored, so peppering it with MongoDB.Bson attributes is not ideal. You can configure how MongoDB.Driver should read and store decimals with this config instead.

BsonSerializer.RegisterSerializer(
  typeof(decimal),
   new DecimalSerializer(BsonType.Double,
   new RepresentationConverter(
     true, // allow overflow, return decimal.MinValue or decimal.MaxValue instead
     true //allow truncation
    ))
 );

source


Related Articles