[CSHARP-1329] Decimal trancation issuewhen running the aggegate Created: 20/Jun/15  Updated: 20/Jun/15  Resolved: 20/Jun/15

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Lenny Granovsky Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File jira issue submission.cs    
Issue Links:
Duplicate
duplicates CSHARP-1321 Custom Serializers in $group Closed

 Description   

Due to space limitation I attached all code as a file.
Consider code sample 1 and 2. They do exactly the same aggregation. They output result using the same LiabilitySetTotals class. This class has few decimal properties. In the DB those values are double. Therefore those properties have [BsonRepresentation(BsonType.Double, AllowTruncation = true)] attribute.

When I use "inline" style of building group expression for aggregation using BsonDocument, output result as a document and convert it to my LiabilitySetTotals, all works fine.

But when I use Linq to build group expression using the LiabilitySetTotals directly, I get an error:
System.FormatException : An error occurred while deserializing the TotalAmount property of class ...LiabilitySetTotals: Truncation resulted in data loss.

It looks like aggregation does not pay attention to BsonRepresentation attribute.



 Comments   
Comment by Craig Wilson [ 20/Jun/15 ]

Thanks Lenny,

This is the same problem as CSHARP-1321. When that gets handled, this will as well. It relates to the fact that the resulting type from the server may not be the same type as the aggregate. For instance, what does 1.0 + 1 result in? Certainly, the result is a likely a double in this case, but what serializer do we use? Either we use the standard double serializer, or we peruse all the fields inside the expression and see if there is a match. That works well until there are 2 matching serializers inside.

Anyways, we'll figure something sensible out. Thanks for the report.
Craig

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