- 修复 MySqlProvider .NetFramework 下可能报初始化类型错误;

This commit is contained in:
2881099 2023-05-20 17:02:07 +08:00
parent e7177991ad
commit 76b18d84a7
6 changed files with 300 additions and 270 deletions

View File

@ -13,7 +13,10 @@ namespace FreeSql.MySql
public class MySqlProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
{
static MySqlProvider()
static int _firstInit = 1;
static void InitInternal()
{
if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误
{
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisPoint)] = true;
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(MygisLineString)] = true;
@ -41,6 +44,7 @@ namespace FreeSql.MySql
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<T1> CreateSelectProvider<T1>(object dywhere) => new MySqlSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
public override IInsert<T1> CreateInsertProvider<T1>() => new MySqlInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
@ -50,6 +54,7 @@ namespace FreeSql.MySql
public MySqlProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
{
InitInternal();
this.InternalCommonUtils = new MySqlUtils(this);
this.InternalCommonExpression = new MySqlExpression(this.InternalCommonUtils);

View File

@ -21,7 +21,10 @@ namespace FreeSql.PostgreSQL
public class PostgreSQLProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
{
static PostgreSQLProvider()
static int _firstInit = 1;
static void InitInternal()
{
if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误
{
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true;
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true;
@ -107,6 +110,7 @@ namespace FreeSql.PostgreSQL
Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) });
}
}
public override ISelect<T1> CreateSelectProvider<T1>(object dywhere) => new PostgreSQLSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
public override IInsert<T1> CreateInsertProvider<T1>() => new PostgreSQLInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
@ -116,6 +120,7 @@ namespace FreeSql.PostgreSQL
public PostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
{
InitInternal();
this.InternalCommonUtils = new PostgreSQLUtils(this);
this.InternalCommonExpression = new PostgreSQLExpression(this.InternalCommonUtils);

View File

@ -21,7 +21,10 @@ namespace FreeSql.QuestDb
{
public class QuestDbProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
{
static QuestDbProvider()
static int _firstInit = 1;
static void InitInternal()
{
if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误
{
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true;
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true;
@ -120,6 +123,7 @@ namespace FreeSql.QuestDb
service.AddHttpClient();
});
}
}
public override ISelect<T1> CreateSelectProvider<T1>(object dywhere) =>
new QuestDbSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
@ -139,6 +143,7 @@ namespace FreeSql.QuestDb
public QuestDbProvider(string masterConnectionString, string[] slaveConnectionString,
Func<DbConnection> connectionFactory = null)
{
InitInternal();
this.InternalCommonUtils = new QuestDbUtils(this);
this.InternalCommonExpression = new QuestDbExpression(this.InternalCommonUtils);

View File

@ -9,10 +9,14 @@ namespace FreeSql.SqlServer
public class SqlServerProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
{
static SqlServerProvider()
static int _firstInit = 1;
static void InitInternal()
{
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<T1> CreateSelectProvider<T1>(object dywhere) => new SqlServerSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
public override IInsert<T1> CreateInsertProvider<T1>() => new SqlServerInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
@ -22,6 +26,7 @@ namespace FreeSql.SqlServer
public SqlServerProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
{
InitInternal();
this.InternalCommonUtils = new SqlServerUtils(this);
this.InternalCommonExpression = new SqlServerExpression(this.InternalCommonUtils);

View File

@ -9,10 +9,14 @@ namespace FreeSql.Sqlite
public class SqliteProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
{
static SqliteProvider()
static int _firstInit = 1;
static void InitInternal()
{
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<T1> CreateSelectProvider<T1>(object dywhere) => new SqliteSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
public override IInsert<T1> CreateInsertProvider<T1>() => new SqliteInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
@ -22,6 +26,7 @@ namespace FreeSql.Sqlite
public SqliteProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
{
InitInternal();
this.InternalCommonUtils = new SqliteUtils(this);
this.InternalCommonExpression = new SqliteExpression(this.InternalCommonUtils);

View File

@ -16,7 +16,10 @@ namespace FreeSql.Xugu
public class XuguProvider<TMark> : BaseDbProvider, IFreeSql<TMark>
{
static XuguProvider()
static int _firstInit = 1;
static void InitInternal()
{
if (Interlocked.Exchange(ref _firstInit, 0) == 1) //不能放在 static ctor .NetFramework 可能报初始化类型错误
{
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BigInteger)] = true;
Utils.dicExecuteArrayRowReadClassOrTuple[typeof(BitArray)] = true;
@ -93,6 +96,7 @@ namespace FreeSql.Xugu
Select0Provider._dicMethodDataReaderGetValue[typeof(Guid)] = typeof(DbDataReader).GetMethod("GetGuid", new Type[] { typeof(int) });
}
}
public override ISelect<T1> CreateSelectProvider<T1>(object dywhere) => new XuguSelect<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
public override IInsert<T1> CreateInsertProvider<T1>() => new XuguInsert<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression);
@ -102,6 +106,7 @@ namespace FreeSql.Xugu
public XuguProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
{
InitInternal();
this.InternalCommonUtils = new XuguUtils(this);
this.InternalCommonExpression = new XuguExpression(this.InternalCommonUtils);