From a1904bf1131308c5c533030988ded74c7e137197 Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 26 Apr 2023 23:46:30 +0800 Subject: [PATCH] Set the precision to be maximum of 28 (Jet limit). When using property.HasConversion() the default for EF Core is with precision 38 and scale 17 which is passed Jet's limit --- .../Storage/Internal/JetDecimalTypeMapping.cs | 15 ++++++++++++++- test/EFCore.Jet.FunctionalTests/config.json | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/EFCore.Jet/Storage/Internal/JetDecimalTypeMapping.cs b/src/EFCore.Jet/Storage/Internal/JetDecimalTypeMapping.cs index 5b313a6..12de982 100644 --- a/src/EFCore.Jet/Storage/Internal/JetDecimalTypeMapping.cs +++ b/src/EFCore.Jet/Storage/Internal/JetDecimalTypeMapping.cs @@ -53,7 +53,20 @@ namespace EntityFrameworkCore.Jet.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) - => new JetDecimalTypeMapping(parameters); + { + var precision = parameters.Precision; + var scale = parameters.Scale; + if (parameters.Precision is > 28) + { + int prec_diff = parameters.Precision.Value - 28; + precision = 28; + if (parameters.Scale is > 28) + { + scale = parameters.Scale.Value - prec_diff; + } + } + return new JetDecimalTypeMapping(parameters.WithPrecisionAndScale(precision, scale)); + } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/test/EFCore.Jet.FunctionalTests/config.json b/test/EFCore.Jet.FunctionalTests/config.json index 6c66070..d97040e 100644 --- a/test/EFCore.Jet.FunctionalTests/config.json +++ b/test/EFCore.Jet.FunctionalTests/config.json @@ -1,7 +1,7 @@ { - "Test": { - "Jet": { - "DefaultConnection": "DBQ=Jet.accdb" - } + "Test": { + "Jet": { + "DefaultConnection": "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Jet.accdb;Persist Security Info=False;" } + } }