Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2607

BsonDefaultValue does not accept decimals.

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.8.0
    • Component/s: None
    • None
    • Environment:
      MongoDB version 4.0.6
      .Core 2.2
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      [BsonDefaultValue(0m)]  shows the compilation error: Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

      However if used with an integer in an object plroperty such as:

      [BsonDefaultValue(0)]

      public decimal Amount { get; set; }

      And then subsequently loading a record with no value for Amount from the database,   the error Unable to cast object of type 'System.Int32' to type 'System.Decimal' is thrown.

      So it appears that you cannot set a default of the correct type for decimal currently.

       

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            tarheit Tim Arheit
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: