From 3a453d918dd7a3742df82c3240aa3dbbe20ef2e5 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Wed, 5 Jan 2022 12:35:44 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20JsonMap=20=E4=B8=8E?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E5=B1=9E=E6=80=A7=E7=9A=84=E8=81=94=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8A=A5=E9=94=99=E7=9A=84=20bug=EF=BC=9B#99?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FreeSql.Extensions.JsonMap/JsonMapCore.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs b/Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs index 60b0e0b1..fb901249 100644 --- a/Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs +++ b/Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs @@ -14,6 +14,7 @@ public static class FreeSqlJsonMapCoreExtensions static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod("SerializeObject", new[] { typeof(object), typeof(JsonSerializerSettings) }); static ConcurrentDictionary> _dicJsonMapFluentApi = new ConcurrentDictionary>(); + static object _concurrentObj = new object(); public static ColumnFluent JsonMap(this ColumnFluent col) { @@ -52,13 +53,17 @@ public static class FreeSqlJsonMapCoreExtensions e.ModifyResult.StringLength = -2; if (_dicTypes.TryAdd(e.Property.PropertyType, true)) { - FreeSql.Internal.Utils.GetDataReaderValueBlockExpressionObjectToStringIfThenElse.Add((LabelTarget returnTarget, Expression valueExp, Expression elseExp, Type type) => + lock (_concurrentObj) { - return Expression.IfThenElse( - Expression.TypeIs(valueExp, e.Property.PropertyType), - Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)), - elseExp); - }); + FreeSql.Internal.Utils.dicExecuteArrayRowReadClassOrTuple[e.Property.PropertyType] = true; + FreeSql.Internal.Utils.GetDataReaderValueBlockExpressionObjectToStringIfThenElse.Add((LabelTarget returnTarget, Expression valueExp, Expression elseExp, Type type) => + { + return Expression.IfThenElse( + Expression.TypeIs(valueExp, e.Property.PropertyType), + Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)), + elseExp); + }); + } } } };