[CSHARP-2638] Truncation resulted in data loss when Sum (Linq) Created: 14/Jun/19  Updated: 25/Jun/20  Resolved: 25/Jun/20

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.8.0, 2.8.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mini Dev Assignee: Wan Bachtiar
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Good morning,

I'm face with this issue:

I have property Total in my MongoDB stored as Double type.

I get all Total as IQueryable<decimal> in my c# code and I call Sum but I received this error:

Truncation resulted in data loss

Code is:

var foo = bar.GetCollection<MyClass>("MyCollectionName").AsQueryable()
.Where(x => x.MyProperty == 10)
.Sum(x => x.Total);

 This not works

 

This problem there is not if I use IEnumerable:

var foo = bar.GetCollection<MyClass>("MyCollectionName").AsQueryable()
.Where(x => x.MyProperty == 10).AsEnumerable()
.Sum(x => x.Total);

This works

 



 Comments   
Comment by Rachelle Palmer [ 25/Jun/20 ]

Hi there, thank you for reaching out to MongoDB. As this sounds more like a support issue, I wanted to give you some resources to get this question answered more quickly:

  • our MongoDB support portal, located at support.mongodb.com
  • our MongoDB community forums, located here
  • If you are an Atlas customer, there is free support offered 24/7 in the lower right hand corner of the UI.

Thank you!
Rachelle

Comment by Mini Dev [ 02/Jul/19 ]

I solved with the following attribute:

[BsonRepresentation(BsonType.Double, AllowTruncation = true)]

Generated at Wed Feb 07 21:43:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.