From dc049d804dbdbcea81737762deab6da2a998d78c Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Wed, 26 Apr 2023 23:44:55 +0800 Subject: [PATCH] Do the same clr type check when mapping "text" as what we do for other store type mappings. This allows conversions do work better (e.g. originally a mappingInfo with a System.Char type was passed in with store type of "text" and a variable length or unbounded string type was returned but with clr type of System.String. Going with the extra checked returns null and gets EF Core to find a converter and then do the mapping again on the converted type --- .../Storage/Internal/JetTypeMappingSource.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/EFCore.Jet/Storage/Internal/JetTypeMappingSource.cs b/src/EFCore.Jet/Storage/Internal/JetTypeMappingSource.cs index 1b4d127..3bae256 100644 --- a/src/EFCore.Jet/Storage/Internal/JetTypeMappingSource.cs +++ b/src/EFCore.Jet/Storage/Internal/JetTypeMappingSource.cs @@ -275,9 +275,20 @@ namespace EntityFrameworkCore.Jet.Storage.Internal if (storeTypeNameBase!.Equals("text", StringComparison.OrdinalIgnoreCase) && !mappingInfo.IsFixedLength.GetValueOrDefault()) { - return mappingInfo.Size.GetValueOrDefault() > 0 - ? _variableLengthUnicodeString - : _unboundedUnicodeString; + if (mappingInfo.Size.GetValueOrDefault() > 0) + { + return clrType == null + || _variableLengthUnicodeString.ClrType == clrType + ? _variableLengthUnicodeString + : null; + } + else + { + return clrType == null + || _unboundedUnicodeString.ClrType == clrType + ? _unboundedUnicodeString + : null; + } } if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping)