googleapis / dotnet-spanner-entity-framework

Apache License 2.0
26 stars 13 forks source link

Save update in a Decimal property - cast error to SpannerNumeric #385

Closed alwydl closed 4 months ago

alwydl commented 11 months ago

Environment details

Steps to reproduce

  1. Using EF create a class with a property decimal
  2. update-database
  3. create 1 record
  4. recover the value of that record and update any other property
  5. await context.SavechangesAsync()

exception message: Unable to cast object of type 'System.Decimal' to type 'Google.Cloud.Spanner.V1.SpannerNumeric'.

Error stacktrace

at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals(Object left, Object right) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectValueChange(InternalEntityEntry entry, IProperty property) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager) at Microsoft.EntityFrameworkCore.DbContext.d__60.MoveNext() at Inpro_Models.Repositories.EcommerceOrderREP.d__1.MoveNext() in D:\Codes\InovarPro\WebServices\Inpro WebServices\Inpro_Models\Repositories\EcommerceOrderREP.cs:line 41

olavloite commented 4 months ago

Yes, this was unfortunately a mistake in the documentation. decimal is not supported for NUMERIC columns. Instead, the SpannerNumeric type must be used. The documentation regarding this will be updated in #405