-
Type: Improvement
-
Resolution: Done
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
(copied to CRM)
-
Fully Compatible
-
Dotnet Drivers
-
Not Needed
Consider the following class:
private class C { public int Id { get; set; } [BsonRepresentation(BsonType.Decimal128)] public decimal D1 { get; set; } [BsonRepresentation(BsonType.Decimal128)] public decimal D2 { get; set; } [BsonRepresentation(BsonType.String)] public decimal DS1 { get; set; } [BsonRepresentation(BsonType.String)] public decimal DS2 { get; set; } }
The following query works:
var queryable = collection.AsQueryable()
.Select(x => x.D2 - x.D1);
because both `D1` and `D2` are stored as `Decimal128` values in the database.
The following query should throw:
var queryable = collection.AsQueryable()
.Select(x => x.DS2 - x.D1);
Because `DS2` and `D1` are not serialized the same way.
And the following query should throw:
var queryable = collection.AsQueryable()
.Select(x => x.DS2 - x.DS1);
because while `DS2` and `DS1` are serialized the same way they are serialized as `strings` and therefore this calculation cannot be done server-side.
There is already code to catch these conditions but it needs to be changed so that the error messages are more informative.
In the first case the error message should be:
"Expression not supported: (x.DS2 - x.D1) because operands are serialized differently."
And in the second case the error message should be:
"Expression not supported: (x.DS2 - x.DS1) because operands are not serialized using a numeric representation."