From 76b18d84a79e5d3d9761fa18a1d1ccf8ee339dc0 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Sat, 20 May 2023 17:02:07 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20MySqlProvider=20.NetFr?= =?UTF-8?q?amework=20=E4=B8=8B=E5=8F=AF=E8=83=BD=E6=8A=A5=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FreeSql.Provider.MySql/MySqlProvider.cs | 53 ++--- .../PostgreSQLProvider.cs | 155 +++++++------- .../QuestDbProvider.cs | 197 +++++++++--------- .../SqlServerProvider.cs | 9 +- .../FreeSql.Provider.Sqlite/SqliteProvider.cs | 9 +- .../FreeSql.Provider.Xugu/XuguProvider.cs | 147 ++++++------- 6 files changed, 300 insertions(+), 270 deletions(-) diff --git a/Providers/FreeSql.Provider.MySql/MySqlProvider.cs b/Providers/FreeSql.Provider.MySql/MySqlProvider.cs index d75fd27f..63bda072 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlProvider.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlProvider.cs @@ -13,33 +13,37 @@ namespace FreeSql.MySql public class MySqlProvider : BaseDbProvider, IFreeSql { - static MySqlProvider() + static int _firstInit = 1; + static void InitInternal() { - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisLineString)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisPolygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisMultiPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisMultiLineString)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisMultiPolygon)] = true; - - var MethodMygisGeometryParse = typeof(MygisGeometry).GetMethod("Parse", new[] { typeof(string) }); - Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) => + if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误 { - switch (type.FullName) - { - case "MygisPoint": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisPoint))); - case "MygisLineString": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisLineString))); - case "MygisPolygon": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisPolygon))); - case "MygisMultiPoint": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisMultiPoint))); - case "MygisMultiLineString": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisMultiLineString))); - case "MygisMultiPolygon": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisMultiPolygon))); - } - return null; - }); + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisLineString)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisPolygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisMultiPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisMultiLineString)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisMultiPolygon)] = true; - Select0Provider._dicMethodDataReaderGetValueOverride[DataType.MySql] = new Dictionary(); - Select0Provider._dicMethodDataReaderGetValueOverride[DataType.MySql][typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); - Select0Provider._dicMethodDataReaderGetValueOverride[DataType.MySql][typeof(DateTimeOffset)] = typeof(DbDataReader).GetMethod("GetDateTime", new Type[] { typeof(int) }); + var MethodMygisGeometryParse = typeof(MygisGeometry).GetMethod("Parse", new[] { typeof(string) }); + Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) => + { + switch (type.FullName) + { + case "MygisPoint": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisPoint))); + case "MygisLineString": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisLineString))); + case "MygisPolygon": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisPolygon))); + case "MygisMultiPoint": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisMultiPoint))); + case "MygisMultiLineString": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisMultiLineString))); + case "MygisMultiPolygon": return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodMygisGeometryParse, Expression.Convert(valueExp, typeof(string))), typeof(MygisMultiPolygon))); + } + return null; + }); + + Select0Provider._dicMethodDataReaderGetValueOverride[DataType.MySql] = new Dictionary(); + Select0Provider._dicMethodDataReaderGetValueOverride[DataType.MySql][typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + Select0Provider._dicMethodDataReaderGetValueOverride[DataType.MySql][typeof(DateTimeOffset)] = typeof(DbDataReader).GetMethod("GetDateTime", new Type[] { typeof(int) }); + } } public override ISelect CreateSelectProvider(object dywhere) => new MySqlSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); @@ -50,6 +54,7 @@ namespace FreeSql.MySql public MySqlProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { + InitInternal(); this.InternalCommonUtils = new MySqlUtils(this); this.InternalCommonExpression = new MySqlExpression(this.InternalCommonUtils); diff --git a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLProvider.cs b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLProvider.cs index 3ee230ca..eb5dc682 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLProvider.cs +++ b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLProvider.cs @@ -21,91 +21,95 @@ namespace FreeSql.PostgreSQL public class PostgreSQLProvider : BaseDbProvider, IFreeSql { - static PostgreSQLProvider() + static int _firstInit = 1; + static void InitInternal() { - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLine)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLSeg)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlBox)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPath)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPolygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlCircle)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof((IPAddress Address, int Subnet))] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(IPAddress)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PhysicalAddress)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误 + { + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLine)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLSeg)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlBox)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPath)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPolygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlCircle)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof((IPAddress Address, int Subnet))] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(IPAddress)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PhysicalAddress)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisLineString)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPolygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiLineString)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPolygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometry)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometryCollection)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisLineString)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPolygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiLineString)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPolygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometry)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometryCollection)] = true; #if nts - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.Point)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.LineString)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.Polygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.MultiPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.MultiLineString)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.MultiPolygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.Geometry)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.GeometryCollection)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.Point)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.LineString)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.Polygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.MultiPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.MultiLineString)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.MultiPolygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.Geometry)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NetTopologySuite.Geometries.GeometryCollection)] = true; #endif - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(Dictionary)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JToken)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JObject)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JArray)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(Dictionary)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JToken)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JObject)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JArray)] = true; - var MethodJTokenFromObject = typeof(JToken).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJObjectFromObject = typeof(JObject).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJArrayFromObject = typeof(JArray).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) }); - var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) }); - var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) }); - var MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); - var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null); - Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) => - { - switch (type.FullName) + var MethodJTokenFromObject = typeof(JToken).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJObjectFromObject = typeof(JObject).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJArrayFromObject = typeof(JArray).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) }); + var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) }); + var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) }); + var MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); + var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null); + Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) => { - case "Newtonsoft.Json.Linq.JToken": + switch (type.FullName) + { + case "Newtonsoft.Json.Linq.JToken": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenParse, Expression.Convert(valueExp, typeof(string))), typeof(JToken))), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenFromObject, valueExp), typeof(JToken)))); + case "Newtonsoft.Json.Linq.JObject": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectParse, Expression.Convert(valueExp, typeof(string))), typeof(JObject))), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectFromObject, valueExp), typeof(JObject)))); + case "Newtonsoft.Json.Linq.JArray": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayParse, Expression.Convert(valueExp, typeof(string))), typeof(JArray))), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayFromObject, valueExp), typeof(JArray)))); + case "Npgsql.LegacyPostgis.PostgisGeometry": + return Expression.Return(returnTarget, valueExp); + case "NetTopologySuite.Geometries.Geometry": + return Expression.Return(returnTarget, valueExp); + } + if (typeof(IList).IsAssignableFrom(type)) return Expression.IfThenElse( Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenParse, Expression.Convert(valueExp, typeof(string))), typeof(JToken))), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenFromObject, valueExp), typeof(JToken)))); - case "Newtonsoft.Json.Linq.JObject": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectParse, Expression.Convert(valueExp, typeof(string))), typeof(JObject))), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectFromObject, valueExp), typeof(JObject)))); - case "Newtonsoft.Json.Linq.JArray": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayParse, Expression.Convert(valueExp, typeof(string))), typeof(JArray))), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayFromObject, valueExp), typeof(JArray)))); - case "Npgsql.LegacyPostgis.PostgisGeometry": - return Expression.Return(returnTarget, valueExp); - case "NetTopologySuite.Geometries.Geometry": - return Expression.Return(returnTarget, valueExp); - } - if (typeof(IList).IsAssignableFrom(type)) - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(valueExp, typeof(string)), Expression.Constant(type, typeof(Type))), type)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), Expression.Constant(type, typeof(Type))), type))); - return null; - }); - - Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(valueExp, typeof(string)), Expression.Constant(type, typeof(Type))), type)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), Expression.Constant(type, typeof(Type))), type))); + return null; + }); + + Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + } } public override ISelect CreateSelectProvider(object dywhere) => new PostgreSQLSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); @@ -116,6 +120,7 @@ namespace FreeSql.PostgreSQL public PostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { + InitInternal(); this.InternalCommonUtils = new PostgreSQLUtils(this); this.InternalCommonExpression = new PostgreSQLExpression(this.InternalCommonUtils); diff --git a/Providers/FreeSql.Provider.QuestDb/QuestDbProvider.cs b/Providers/FreeSql.Provider.QuestDb/QuestDbProvider.cs index f7a16dd8..f937b829 100644 --- a/Providers/FreeSql.Provider.QuestDb/QuestDbProvider.cs +++ b/Providers/FreeSql.Provider.QuestDb/QuestDbProvider.cs @@ -21,104 +21,108 @@ namespace FreeSql.QuestDb { public class QuestDbProvider : BaseDbProvider, IFreeSql { - static QuestDbProvider() + static int _firstInit = 1; + static void InitInternal() { - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPoint)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLine)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLSeg)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlBox)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPath)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPolygon)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlCircle)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof((IPAddress Address, int Subnet))] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(IPAddress)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PhysicalAddress)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(Dictionary)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JToken)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JObject)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JArray)] = true; - - var MethodJTokenFromObject = typeof(JToken).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJObjectFromObject = typeof(JObject).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJArrayFromObject = typeof(JArray).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) }); - var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) }); - var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) }); - var MethodJsonConvertDeserializeObject = - typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); - var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, - null, new[] { typeof(object) }, null); - Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add( - (LabelTarget returnTarget, Expression valueExp, Type type) => - { - switch (type.FullName) - { - case "Newtonsoft.Json.Linq.JToken": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, - Expression.TypeAs( - Expression.Call(MethodJTokenParse, - Expression.Convert(valueExp, typeof(string))), typeof(JToken))), - Expression.Return(returnTarget, - Expression.TypeAs(Expression.Call(MethodJTokenFromObject, valueExp), - typeof(JToken)))); - case "Newtonsoft.Json.Linq.JObject": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, - Expression.TypeAs( - Expression.Call(MethodJObjectParse, - Expression.Convert(valueExp, typeof(string))), typeof(JObject))), - Expression.Return(returnTarget, - Expression.TypeAs(Expression.Call(MethodJObjectFromObject, valueExp), - typeof(JObject)))); - case "Newtonsoft.Json.Linq.JArray": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, - Expression.TypeAs( - Expression.Call(MethodJArrayParse, - Expression.Convert(valueExp, typeof(string))), typeof(JArray))), - Expression.Return(returnTarget, - Expression.TypeAs(Expression.Call(MethodJArrayFromObject, valueExp), - typeof(JArray)))); - case "Npgsql.LegacyPostgis.PostgisGeometry": - return Expression.Return(returnTarget, valueExp); - case "NetTopologySuite.Geometries.Geometry": - return Expression.Return(returnTarget, valueExp); - } - - if (typeof(IList).IsAssignableFrom(type)) - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, - Expression.TypeAs( - Expression.Call(MethodJsonConvertDeserializeObject, - Expression.Convert(valueExp, typeof(string)), - Expression.Constant(type, typeof(Type))), type)), - Expression.Return(returnTarget, - Expression.TypeAs( - Expression.Call(MethodJsonConvertDeserializeObject, - Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), - Expression.Constant(type, typeof(Type))), type))); - return null; - }); - - Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = - typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); - - QuestDbContainer.Initialize(service => + if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误 { - service.AddHttpClient(); - }); + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPoint)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLine)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLSeg)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlBox)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPath)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPolygon)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlCircle)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof((IPAddress Address, int Subnet))] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(IPAddress)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PhysicalAddress)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(Dictionary)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JToken)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JObject)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JArray)] = true; + + var MethodJTokenFromObject = typeof(JToken).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJObjectFromObject = typeof(JObject).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJArrayFromObject = typeof(JArray).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) }); + var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) }); + var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) }); + var MethodJsonConvertDeserializeObject = + typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); + var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, + null, new[] { typeof(object) }, null); + Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add( + (LabelTarget returnTarget, Expression valueExp, Type type) => + { + switch (type.FullName) + { + case "Newtonsoft.Json.Linq.JToken": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, + Expression.TypeAs( + Expression.Call(MethodJTokenParse, + Expression.Convert(valueExp, typeof(string))), typeof(JToken))), + Expression.Return(returnTarget, + Expression.TypeAs(Expression.Call(MethodJTokenFromObject, valueExp), + typeof(JToken)))); + case "Newtonsoft.Json.Linq.JObject": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, + Expression.TypeAs( + Expression.Call(MethodJObjectParse, + Expression.Convert(valueExp, typeof(string))), typeof(JObject))), + Expression.Return(returnTarget, + Expression.TypeAs(Expression.Call(MethodJObjectFromObject, valueExp), + typeof(JObject)))); + case "Newtonsoft.Json.Linq.JArray": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, + Expression.TypeAs( + Expression.Call(MethodJArrayParse, + Expression.Convert(valueExp, typeof(string))), typeof(JArray))), + Expression.Return(returnTarget, + Expression.TypeAs(Expression.Call(MethodJArrayFromObject, valueExp), + typeof(JArray)))); + case "Npgsql.LegacyPostgis.PostgisGeometry": + return Expression.Return(returnTarget, valueExp); + case "NetTopologySuite.Geometries.Geometry": + return Expression.Return(returnTarget, valueExp); + } + + if (typeof(IList).IsAssignableFrom(type)) + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, + Expression.TypeAs( + Expression.Call(MethodJsonConvertDeserializeObject, + Expression.Convert(valueExp, typeof(string)), + Expression.Constant(type, typeof(Type))), type)), + Expression.Return(returnTarget, + Expression.TypeAs( + Expression.Call(MethodJsonConvertDeserializeObject, + Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), + Expression.Constant(type, typeof(Type))), type))); + return null; + }); + + Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = + typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + + QuestDbContainer.Initialize(service => + { + service.AddHttpClient(); + }); + } } public override ISelect CreateSelectProvider(object dywhere) => @@ -139,6 +143,7 @@ namespace FreeSql.QuestDb public QuestDbProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { + InitInternal(); this.InternalCommonUtils = new QuestDbUtils(this); this.InternalCommonExpression = new QuestDbExpression(this.InternalCommonUtils); diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerProvider.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerProvider.cs index bb26187b..fdb7635f 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerProvider.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerProvider.cs @@ -9,9 +9,13 @@ namespace FreeSql.SqlServer public class SqlServerProvider : BaseDbProvider, IFreeSql { - static SqlServerProvider() + static int _firstInit = 1; + static void InitInternal() { - Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误 + { + Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + } } public override ISelect CreateSelectProvider(object dywhere) => new SqlServerSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); @@ -22,6 +26,7 @@ namespace FreeSql.SqlServer public SqlServerProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { + InitInternal(); this.InternalCommonUtils = new SqlServerUtils(this); this.InternalCommonExpression = new SqlServerExpression(this.InternalCommonUtils); diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs b/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs index b28631fc..ad936938 100644 --- a/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs +++ b/Providers/FreeSql.Provider.Sqlite/SqliteProvider.cs @@ -9,9 +9,13 @@ namespace FreeSql.Sqlite public class SqliteProvider : BaseDbProvider, IFreeSql { - static SqliteProvider() + static int _firstInit = 1; + static void InitInternal() { - Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误 + { + Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + } } public override ISelect CreateSelectProvider(object dywhere) => new SqliteSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); @@ -22,6 +26,7 @@ namespace FreeSql.Sqlite public SqliteProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { + InitInternal(); this.InternalCommonUtils = new SqliteUtils(this); this.InternalCommonExpression = new SqliteExpression(this.InternalCommonUtils); diff --git a/Providers/FreeSql.Provider.Xugu/XuguProvider.cs b/Providers/FreeSql.Provider.Xugu/XuguProvider.cs index 92122c19..4093f58c 100644 --- a/Providers/FreeSql.Provider.Xugu/XuguProvider.cs +++ b/Providers/FreeSql.Provider.Xugu/XuguProvider.cs @@ -16,82 +16,86 @@ namespace FreeSql.Xugu public class XuguProvider : BaseDbProvider, IFreeSql { - static XuguProvider() + static int _firstInit = 1; + static void InitInternal() { - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true; - Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPoint)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLine)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLSeg)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlBox)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPath)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPolygon)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlCircle)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof((IPAddress Address, int Subnet))] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(IPAddress)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PhysicalAddress)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; - - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPoint)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisLineString)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPolygon)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPoint)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiLineString)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPolygon)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometry)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometryCollection)] = true; - - - - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(Dictionary)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JToken)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JObject)] = true; - //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JArray)] = true; - - var MethodJTokenFromObject = typeof(JToken).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJObjectFromObject = typeof(JObject).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJArrayFromObject = typeof(JArray).GetMethod("FromObject", new[] { typeof(object) }); - var MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) }); - var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) }); - var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) }); - var MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); - var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null); - Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) => + if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误 { - switch (type.FullName) + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true; + Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPoint)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLine)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlLSeg)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlBox)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPath)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlPolygon)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlCircle)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof((IPAddress Address, int Subnet))] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(IPAddress)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PhysicalAddress)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(NpgsqlRange)] = true; + + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPoint)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisLineString)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisPolygon)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPoint)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiLineString)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisMultiPolygon)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometry)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(PostgisGeometryCollection)] = true; + + + + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(Dictionary)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JToken)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JObject)] = true; + //Utils.dicExecuteArrayRowReadClassOrTuple[typeof(JArray)] = true; + + var MethodJTokenFromObject = typeof(JToken).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJObjectFromObject = typeof(JObject).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJArrayFromObject = typeof(JArray).GetMethod("FromObject", new[] { typeof(object) }); + var MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) }); + var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) }); + var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) }); + var MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) }); + var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null); + Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) => { - case "Newtonsoft.Json.Linq.JToken": + switch (type.FullName) + { + case "Newtonsoft.Json.Linq.JToken": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenParse, Expression.Convert(valueExp, typeof(string))), typeof(JToken))), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenFromObject, valueExp), typeof(JToken)))); + case "Newtonsoft.Json.Linq.JObject": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectParse, Expression.Convert(valueExp, typeof(string))), typeof(JObject))), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectFromObject, valueExp), typeof(JObject)))); + case "Newtonsoft.Json.Linq.JArray": + return Expression.IfThenElse( + Expression.TypeIs(valueExp, typeof(string)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayParse, Expression.Convert(valueExp, typeof(string))), typeof(JArray))), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayFromObject, valueExp), typeof(JArray)))); + //case "Npgsql.LegacyPostgis.PostgisGeometry": + // return Expression.Return(returnTarget, valueExp); + //case "NetTopologySuite.Geometries.Geometry": + // return Expression.Return(returnTarget, valueExp); + } + if (typeof(IList).IsAssignableFrom(type)) return Expression.IfThenElse( Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenParse, Expression.Convert(valueExp, typeof(string))), typeof(JToken))), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJTokenFromObject, valueExp), typeof(JToken)))); - case "Newtonsoft.Json.Linq.JObject": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectParse, Expression.Convert(valueExp, typeof(string))), typeof(JObject))), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJObjectFromObject, valueExp), typeof(JObject)))); - case "Newtonsoft.Json.Linq.JArray": - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayParse, Expression.Convert(valueExp, typeof(string))), typeof(JArray))), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJArrayFromObject, valueExp), typeof(JArray)))); - //case "Npgsql.LegacyPostgis.PostgisGeometry": - // return Expression.Return(returnTarget, valueExp); - //case "NetTopologySuite.Geometries.Geometry": - // return Expression.Return(returnTarget, valueExp); - } - if (typeof(IList).IsAssignableFrom(type)) - return Expression.IfThenElse( - Expression.TypeIs(valueExp, typeof(string)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(valueExp, typeof(string)), Expression.Constant(type, typeof(Type))), type)), - Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), Expression.Constant(type, typeof(Type))), type))); - return null; - }); - - Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(valueExp, typeof(string)), Expression.Constant(type, typeof(Type))), type)), + Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), Expression.Constant(type, typeof(Type))), type))); + return null; + }); + + Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) }); + } } public override ISelect CreateSelectProvider(object dywhere) => new XuguSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); @@ -102,6 +106,7 @@ namespace FreeSql.Xugu public XuguProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { + InitInternal(); this.InternalCommonUtils = new XuguUtils(this); this.InternalCommonExpression = new XuguExpression(this.InternalCommonUtils);