@@ -13,33 +13,37 @@ namespace FreeSql.MySql
1313
1414 public class MySqlProvider < TMark > : BaseDbProvider , IFreeSql < TMark >
1515 {
16- static MySqlProvider ( )
16+ static int _firstInit = 1 ;
17+ static void InitInternal ( )
1718 {
18- Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisPoint ) ] = true ;
19- Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisLineString ) ] = true ;
20- Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisPolygon ) ] = true ;
21- Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisMultiPoint ) ] = true ;
22- Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisMultiLineString ) ] = true ;
23- Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisMultiPolygon ) ] = true ;
24-
25- var MethodMygisGeometryParse = typeof ( MygisGeometry ) . GetMethod ( "Parse" , new [ ] { typeof ( string ) } ) ;
26- Utils . GetDataReaderValueBlockExpressionSwitchTypeFullName . Add ( ( LabelTarget returnTarget , Expression valueExp , Type type ) =>
19+ if ( Interlocked . Exchange ( ref _firstInit , 0 ) == 1 ) //不能放在 static ctor .NetFramework 可能报初始化类型错误
2720 {
28- switch ( type . FullName )
21+ Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisPoint ) ] = true ;
22+ Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisLineString ) ] = true ;
23+ Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisPolygon ) ] = true ;
24+ Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisMultiPoint ) ] = true ;
25+ Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisMultiLineString ) ] = true ;
26+ Utils . dicExecuteArrayRowReadClassOrTuple [ typeof ( MygisMultiPolygon ) ] = true ;
27+
28+ var MethodMygisGeometryParse = typeof ( MygisGeometry ) . GetMethod ( "Parse" , new [ ] { typeof ( string ) } ) ;
29+ Utils . GetDataReaderValueBlockExpressionSwitchTypeFullName . Add ( ( LabelTarget returnTarget , Expression valueExp , Type type ) =>
2930 {
30- case "MygisPoint" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisPoint ) ) ) ;
31- case "MygisLineString" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisLineString ) ) ) ;
32- case "MygisPolygon" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisPolygon ) ) ) ;
33- case "MygisMultiPoint" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisMultiPoint ) ) ) ;
34- case "MygisMultiLineString" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisMultiLineString ) ) ) ;
35- case "MygisMultiPolygon" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisMultiPolygon ) ) ) ;
36- }
37- return null ;
38- } ) ;
31+ switch ( type . FullName )
32+ {
33+ case "MygisPoint" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisPoint ) ) ) ;
34+ case "MygisLineString" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisLineString ) ) ) ;
35+ case "MygisPolygon" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisPolygon ) ) ) ;
36+ case "MygisMultiPoint" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisMultiPoint ) ) ) ;
37+ case "MygisMultiLineString" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisMultiLineString ) ) ) ;
38+ case "MygisMultiPolygon" : return Expression . Return ( returnTarget , Expression . TypeAs ( Expression . Call ( MethodMygisGeometryParse , Expression . Convert ( valueExp , typeof ( string ) ) ) , typeof ( MygisMultiPolygon ) ) ) ;
39+ }
40+ return null ;
41+ } ) ;
3942
40- Select0Provider . _dicMethodDataReaderGetValueOverride [ DataType . MySql ] = new Dictionary < Type , MethodInfo > ( ) ;
41- Select0Provider . _dicMethodDataReaderGetValueOverride [ DataType . MySql ] [ typeof ( Guid ) ] = typeof ( DbDataReader ) . GetMethod ( "GetGuid" , new Type [ ] { typeof ( int ) } ) ;
42- Select0Provider . _dicMethodDataReaderGetValueOverride [ DataType . MySql ] [ typeof ( DateTimeOffset ) ] = typeof ( DbDataReader ) . GetMethod ( "GetDateTime" , new Type [ ] { typeof ( int ) } ) ;
43+ Select0Provider . _dicMethodDataReaderGetValueOverride [ DataType . MySql ] = new Dictionary < Type , MethodInfo > ( ) ;
44+ Select0Provider . _dicMethodDataReaderGetValueOverride [ DataType . MySql ] [ typeof ( Guid ) ] = typeof ( DbDataReader ) . GetMethod ( "GetGuid" , new Type [ ] { typeof ( int ) } ) ;
45+ Select0Provider . _dicMethodDataReaderGetValueOverride [ DataType . MySql ] [ typeof ( DateTimeOffset ) ] = typeof ( DbDataReader ) . GetMethod ( "GetDateTime" , new Type [ ] { typeof ( int ) } ) ;
46+ }
4347 }
4448
4549 public override ISelect < T1 > CreateSelectProvider < T1 > ( object dywhere ) => new MySqlSelect < T1 > ( this , this . InternalCommonUtils , this . InternalCommonExpression , dywhere ) ;
@@ -50,6 +54,7 @@ static MySqlProvider()
5054
5155 public MySqlProvider ( string masterConnectionString , string [ ] slaveConnectionString , Func < DbConnection > connectionFactory = null )
5256 {
57+ InitInternal ( ) ;
5358 this . InternalCommonUtils = new MySqlUtils ( this ) ;
5459 this . InternalCommonExpression = new MySqlExpression ( this . InternalCommonUtils ) ;
5560
0 commit comments