- 优化 IAdo.ConnectionString 使用 UseConnectionFactory 时值为 NULL 的问题;

This commit is contained in:
2881099 2023-01-16 19:16:56 +08:00
parent 32e45dd925
commit 33f11a2066
33 changed files with 131 additions and 32 deletions

View File

@ -800,14 +800,5 @@
<param name="that"></param> <param name="that"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
<summary>
批量注入 Repository可以参考代码自行调整
</summary>
<param name="services"></param>
<param name="globalDataFilter"></param>
<param name="assemblies"></param>
<returns></returns>
</member>
</members> </members>
</doc> </doc>

View File

@ -1,4 +1,4 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using System; using System;
using Xunit; using Xunit;
@ -10,6 +10,14 @@ namespace FreeSql.Tests.Dameng
public void Pool() public void Pool()
{ {
var t1 = g.dameng.Ado.MasterPool.StatisticsFullily; var t1 = g.dameng.Ado.MasterPool.StatisticsFullily;
var connectionString = "data source=127.0.0.1:5236;user id=2user;password=123456789;Pooling=true;poolsize=5";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.Dameng, () => new Dm.DmConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -1,4 +1,4 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using System; using System;
using Xunit; using Xunit;
@ -10,6 +10,14 @@ namespace FreeSql.Tests.Firebird
public void Pool() public void Pool()
{ {
var t1 = g.firebird.Ado.MasterPool.StatisticsFullily; var t1 = g.firebird.Ado.MasterPool.StatisticsFullily;
var connectionString = @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.Firebird, () => new FirebirdSql.Data.FirebirdClient.FbConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -1,5 +1,6 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using System; using System;
using System.Data.OleDb;
using Xunit; using Xunit;
namespace FreeSql.Tests.MsAccess namespace FreeSql.Tests.MsAccess
@ -10,6 +11,14 @@ namespace FreeSql.Tests.MsAccess
public void Pool() public void Pool()
{ {
var t1 = g.msaccess.Ado.MasterPool.StatisticsFullily; var t1 = g.msaccess.Ado.MasterPool.StatisticsFullily;
var connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:/accdb/2007.accdb;max pool size=51";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.MsAccess, () => new OleDbConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -1,4 +1,5 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using MySql.Data.MySqlClient;
using System; using System;
using Xunit; using Xunit;
@ -10,6 +11,14 @@ namespace FreeSql.Tests.MySql
public void Pool() public void Pool()
{ {
var t1 = g.mysql.Ado.MasterPool.StatisticsFullily; var t1 = g.mysql.Ado.MasterPool.StatisticsFullily;
var connectionString = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=51;Allow User Variables=True";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.MySql, () => new MySqlConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -1,4 +1,5 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using Oracle.ManagedDataAccess.Client;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Xunit; using Xunit;
@ -11,6 +12,14 @@ namespace FreeSql.Tests.Oracle
public void Pool() public void Pool()
{ {
var t1 = g.oracle.Ado.MasterPool.StatisticsFullily; var t1 = g.oracle.Ado.MasterPool.StatisticsFullily;
var connectionString = "user id=1user;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=21";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.Oracle, () => new OracleConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -1,4 +1,5 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using Npgsql;
using System; using System;
using Xunit; using Xunit;
@ -10,6 +11,14 @@ namespace FreeSql.Tests.PostgreSQL
public void Pool() public void Pool()
{ {
var t1 = g.pgsql.Ado.MasterPool.StatisticsFullily; var t1 = g.pgsql.Ado.MasterPool.StatisticsFullily;
var connectionString = "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;ArrayNullabilityMode=Always;Pooling=true;Maximum Pool Size=21";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.PostgreSQL, () => new NpgsqlConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -1,4 +1,4 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using FreeSql.Tests.DataContext.SqlServer; using FreeSql.Tests.DataContext.SqlServer;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using NetTaste; using NetTaste;
@ -24,6 +24,14 @@ namespace FreeSql.Tests.SqlServer
public void Pool() public void Pool()
{ {
var t1 = g.sqlserver.Ado.MasterPool.StatisticsFullily; var t1 = g.sqlserver.Ado.MasterPool.StatisticsFullily;
var connectionString = "Data Source=.;Integrated Security=True;Initial Catalog=issues684;Pooling=true;Max Pool Size=31;TrustServerCertificate=true";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.SqlServer, () => new SqlConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]
@ -82,7 +90,7 @@ namespace FreeSql.Tests.SqlServer
fsql.Ado.CommandFluent("dbo.GetICMaxNum", new Dictionary<string, object> fsql.Ado.CommandFluent("dbo.GetICMaxNum", new Dictionary<string, object>
{ {
["TableName"] = "tb1" ["TableName"] = "tb1"
// 更多参数 // 更多参数
}) })
.WithParameter("FInterID", null, p => .WithParameter("FInterID", null, p =>
{ {

View File

@ -1,4 +1,5 @@
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using Microsoft.Data.Sqlite;
using System; using System;
using Xunit; using Xunit;
@ -10,6 +11,14 @@ namespace FreeSql.Tests.Sqlite
public void Pool() public void Pool()
{ {
var t1 = g.sqlite.Ado.MasterPool.StatisticsFullily; var t1 = g.sqlite.Ado.MasterPool.StatisticsFullily;
var connectionString = "data source=:memory:";
using (var t2 = new FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.Sqlite, () => new SqliteConnection(connectionString))
.Build())
{
Assert.Equal(connectionString, t2.Ado.ConnectionString);
}
} }
[Fact] [Fact]

View File

@ -19,7 +19,9 @@ namespace FreeSql.ClickHouse
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.ClickHouse, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.ClickHouse, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -18,6 +18,7 @@ namespace FreeSql.Custom
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
_CreateCommandConnection = pool.TestConnection; _CreateCommandConnection = pool.TestConnection;
_CreateParameterCommand = CreateCommand(); _CreateParameterCommand = CreateCommand();

View File

@ -20,6 +20,7 @@ namespace FreeSql.Custom.MySql
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
return; return;
} }

View File

@ -21,6 +21,7 @@ namespace FreeSql.Custom.Oracle
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
using (var conn = pool.Get()) using (var conn = pool.Get())
UserId = CustomOracleAdo.GetUserId(conn.Value.ConnectionString); UserId = CustomOracleAdo.GetUserId(conn.Value.ConnectionString);

View File

@ -21,6 +21,7 @@ namespace FreeSql.Custom.PostgreSQL
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
return; return;
} }

View File

@ -21,6 +21,7 @@ namespace FreeSql.Custom.SqlServer
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
return; return;
} }

View File

@ -17,7 +17,9 @@ namespace FreeSql.Dameng
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Dameng, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Dameng, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -20,6 +20,7 @@ namespace FreeSql.Firebird
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Firebird, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Firebird, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
_CreateCommandConnection = pool.TestConnection; _CreateCommandConnection = pool.TestConnection;
return; return;

View File

@ -20,6 +20,7 @@ namespace FreeSql.GBase
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.GBase, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.GBase, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
_CreateCommandConnection = pool.TestConnection; _CreateCommandConnection = pool.TestConnection;
return; return;

View File

@ -19,7 +19,9 @@ namespace FreeSql.KingbaseES
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.KingbaseES, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.KingbaseES, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -19,7 +19,9 @@ namespace FreeSql.MsAccess
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MsAccess, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MsAccess, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -23,7 +23,9 @@ namespace FreeSql.MySql
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MySql, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MySql, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -18,7 +18,9 @@ namespace FreeSql.Odbc.Dameng
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcDameng, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcDameng, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -18,7 +18,9 @@ namespace FreeSql.Odbc.Default
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Odbc, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Odbc, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -19,7 +19,9 @@ namespace FreeSql.Odbc.KingbaseES
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcKingbaseES, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcKingbaseES, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -19,7 +19,9 @@ namespace FreeSql.Odbc.MySql
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcMySql, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcMySql, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -18,7 +18,9 @@ namespace FreeSql.Odbc.Oracle
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcOracle, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcOracle, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -19,7 +19,9 @@ namespace FreeSql.Odbc.PostgreSQL
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcPostgreSQL, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcPostgreSQL, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -19,7 +19,9 @@ namespace FreeSql.Odbc.SqlServer
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcSqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcSqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -16,7 +16,9 @@ namespace FreeSql.Oracle
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Oracle, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Oracle, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -21,7 +21,9 @@ namespace FreeSql.PostgreSQL
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.PostgreSQL, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.PostgreSQL, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -19,7 +19,9 @@ namespace FreeSql.ShenTong
base._util = util; base._util = util;
if (connectionFactory != null) if (connectionFactory != null)
{ {
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.ShenTong, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.ShenTong, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool;
return; return;
} }
if (!string.IsNullOrEmpty(masterConnectionString)) if (!string.IsNullOrEmpty(masterConnectionString))

View File

@ -24,6 +24,7 @@ namespace FreeSql.SqlServer
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
_CreateCommandConnection = pool.TestConnection; _CreateCommandConnection = pool.TestConnection;
return; return;

View File

@ -24,6 +24,7 @@ namespace FreeSql.Sqlite
if (connectionFactory != null) if (connectionFactory != null)
{ {
var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Sqlite, connectionFactory); var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Sqlite, connectionFactory);
ConnectionString = pool.TestConnection?.ConnectionString;
MasterPool = pool; MasterPool = pool;
_CreateCommandConnection = pool.TestConnection; _CreateCommandConnection = pool.TestConnection;
return; return;