diff --git a/Extensions/FreeSql.Generator/FreeSql.Generator.csproj b/Extensions/FreeSql.Generator/FreeSql.Generator.csproj
index 390f6b4c..d8deda05 100644
--- a/Extensions/FreeSql.Generator/FreeSql.Generator.csproj
+++ b/Extensions/FreeSql.Generator/FreeSql.Generator.csproj
@@ -12,7 +12,7 @@
使用 FreeSql 快速生成数据库的实体类,安装:dotnet tool install -g FreeSql.Generator
https://github.com/2881099/FreeSql
https://github.com/2881099/FreeSql
- 1.8.1.330
+ 1.9.0-preview0920
FreeSql DbFirst 实体生成器
diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml
index 9c6cd88b..5a0c8bd0 100644
--- a/FreeSql.DbContext/FreeSql.DbContext.xml
+++ b/FreeSql.DbContext/FreeSql.DbContext.xml
@@ -130,13 +130,6 @@
清空状态数据
-
-
- 根据 lambda 条件删除数据
-
-
-
-
添加
diff --git a/FreeSql.Tests/FreeSql.Tests/SqlServer/Curd/SqlServerInsertTest.cs b/FreeSql.Tests/FreeSql.Tests/SqlServer/Curd/SqlServerInsertTest.cs
index 356f5fcf..eb7d8c0f 100644
--- a/FreeSql.Tests/FreeSql.Tests/SqlServer/Curd/SqlServerInsertTest.cs
+++ b/FreeSql.Tests/FreeSql.Tests/SqlServer/Curd/SqlServerInsertTest.cs
@@ -171,6 +171,7 @@ namespace FreeSql.Tests.SqlServer
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
insert.AppendData(items).InsertIdentity().ExecuteSqlBulkCopy();
+ insert.AppendData(items).IgnoreColumns(a => new { a.CreateTime, a.Clicks }).ExecuteSqlBulkCopy();
// System.NotSupportedException:“DataSet does not support System.Nullable<>.”
}
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index b99f558c..330dc4ac 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -2805,6 +2805,21 @@
new { id = 1 } 或者 Dictionary<string, object>
+
+
+ SQL 命令执行类,fsql.Ado.CommandFluent("select * from user where age > ?age", new { age = 25 })
+ .WithConnection(connection)
+ .WithTransaction(transaction)
+ .WithParameter("age", 25)
+ .WithParameter("id", 11)
+ .CommandType(CommandType.Text)
+ .CommandTimeout(60)
+ .Query<T>(); 或者 ExecuteNonQuery/ExecuteScalar/ExecuteDataTable/ExecuteDataSet/ExecuteArray
+
+
+
+
+
测试数据库是否连接正确,本方法执行如下命令:
@@ -3674,6 +3689,43 @@
表达式
+
+
+ 使用指定 DbConnection 连接执行
+
+
+
+
+
+
+ 使用指定 DbTransaction 事务执行
+
+
+
+
+
+
+ 增加参数化对象
+
+ 参数名
+ 参数值
+ 修改本次创建好的参数化对象,比如将 parameterName 参数修改为 Output 类型
+
+
+
+
+ 设置执行的命令类型,SQL文本、或存储过程
+
+
+
+
+
+
+ 设置命令执行超时(秒)
+
+
+
+
当前操作的数据
diff --git a/FreeSql/Interface/IAdo.cs b/FreeSql/Interface/IAdo.cs
index a0e5dde9..69ce18f9 100644
--- a/FreeSql/Interface/IAdo.cs
+++ b/FreeSql/Interface/IAdo.cs
@@ -62,6 +62,21 @@ namespace FreeSql
///
DbParameter[] GetDbParamtersByObject(object obj);
+ ///
+ /// SQL 命令执行类,fsql.Ado.CommandFluent("select * from user where age > ?age", new { age = 25 })
+ /// .WithConnection(connection)
+ /// .WithTransaction(transaction)
+ /// .WithParameter("age", 25)
+ /// .WithParameter("id", 11)
+ /// .CommandType(CommandType.Text)
+ /// .CommandTimeout(60)
+ /// .Query<T>(); 或者 ExecuteNonQuery/ExecuteScalar/ExecuteDataTable/ExecuteDataSet/ExecuteArray
+ ///
+ ///
+ ///
+ ///
+ AdoCommandFluent CommandFluent(string cmdText, object parms = null);
+
///
/// 测试数据库是否连接正确,本方法执行如下命令:
/// MySql/SqlServer/PostgreSQL/达梦/人大金仓/神通: SELECT 1
diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs
index f38845ba..6abba992 100644
--- a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs
+++ b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs
@@ -16,8 +16,8 @@ namespace FreeSql.Internal.CommonProvider
{
protected abstract void ReturnConnection(IObjectPool pool, Object conn, Exception ex);
- protected abstract DbCommand CreateCommand();
- protected abstract DbParameter[] GetDbParamtersByObject(string sql, object obj);
+ public abstract DbCommand CreateCommand();
+ public abstract DbParameter[] GetDbParamtersByObject(string sql, object obj);
public DbParameter[] GetDbParamtersByObject(object obj) => GetDbParamtersByObject("*", obj);
protected bool IsTracePerformance => _util?._orm?.Aop.CommandAfterHandler != null;
@@ -28,6 +28,7 @@ namespace FreeSql.Internal.CommonProvider
public string ConnectionString { get; }
public string[] SlaveConnectionStrings { get; }
public Guid Identifier { get; }
+
protected CommonUtils _util { get; set; }
protected int slaveUnavailables = 0;
private object slaveLock = new object();
@@ -97,6 +98,8 @@ namespace FreeSql.Internal.CommonProvider
//return props;
}
+ public AdoCommandFluent CommandFluent(string cmdText, object parms = null) => new AdoCommandFluent(this, cmdText, parms);
+
public bool ExecuteConnectTest(int commandTimeout = 0)
{
try
diff --git a/FreeSql/Internal/Model/AdoCommandFluent.cs b/FreeSql/Internal/Model/AdoCommandFluent.cs
new file mode 100644
index 00000000..8accc9aa
--- /dev/null
+++ b/FreeSql/Internal/Model/AdoCommandFluent.cs
@@ -0,0 +1,113 @@
+using FreeSql.Internal.CommonProvider;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FreeSql.Internal.Model
+{
+ public class AdoCommandFluent
+ {
+ internal protected AdoProvider Ado { get; protected set; }
+ internal protected DbConnection Connection { get; protected set; }
+ internal protected DbTransaction Transaction { get; protected set; }
+ internal protected CommandType CmdType { get; protected set; } = System.Data.CommandType.Text;
+ internal protected string CmdText { get; protected set; }
+ internal protected int CmdTimeout { get; protected set; }
+ internal protected List CmdParameters { get; } = new List();
+
+ public AdoCommandFluent(AdoProvider ado, string commandText, object parms)
+ {
+ this.Ado = ado;
+ this.CmdText = commandText;
+ this.CmdParameters.AddRange(this.Ado.GetDbParamtersByObject(parms));
+ }
+
+ ///
+ /// 使用指定 DbConnection 连接执行
+ ///
+ ///
+ ///
+ public AdoCommandFluent WithConnection(DbConnection conn)
+ {
+ this.Transaction = null;
+ this.Connection = conn;
+ return this;
+ }
+ ///
+ /// 使用指定 DbTransaction 事务执行
+ ///
+ ///
+ ///
+ public AdoCommandFluent WithTransaction(DbTransaction tran)
+ {
+ this.Transaction = tran;
+ if (tran != null) this.Connection = tran.Connection;
+ return this;
+ }
+
+ ///
+ /// 增加参数化对象
+ ///
+ /// 参数名
+ /// 参数值
+ /// 修改本次创建好的参数化对象,比如将 parameterName 参数修改为 Output 类型
+ ///
+ public AdoCommandFluent WithParameter(string parameterName, object value, Action modify = null)
+ {
+ var param = this.Ado.GetDbParamtersByObject(new Dictionary { [parameterName] = value }).FirstOrDefault();
+ modify?.Invoke(param);
+ this.CmdParameters.Add(param);
+ return this;
+ }
+
+ ///
+ /// 设置执行的命令类型,SQL文本、或存储过程
+ ///
+ ///
+ ///
+ public AdoCommandFluent CommandType(CommandType commandType)
+ {
+ this.CmdType = commandType;
+ return this;
+ }
+ ///
+ /// 设置命令执行超时(秒)
+ ///
+ ///
+ ///
+ public AdoCommandFluent CommandTimeout(int commandTimeout)
+ {
+ this.CmdTimeout = commandTimeout;
+ return this;
+ }
+
+ public int ExecuteNonQuery() => this.Ado.ExecuteNonQuery(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public object ExecuteScalar() => this.Ado.ExecuteScalar(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public DataTable ExecuteDataTable() => this.Ado.ExecuteDataTable(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public DataSet ExecuteDataSet() => this.Ado.ExecuteDataSet(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public object[][] ExecuteArray() => this.Ado.ExecuteArray(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public List Query() => this.Ado.Query(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public NativeTuple, List> Query() => this.Ado.Query(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public NativeTuple, List, List> Query() => this.Ado.Query(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public NativeTuple, List, List, List> Query() => this.Ado.Query(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public NativeTuple, List, List, List, List> Query() => this.Ado.Query(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+
+#if net40
+#else
+ public Task ExecuteNonQueryAsync() => this.Ado.ExecuteNonQueryAsync(this.Connection, this.Transaction, this.CmdType, this.CmdText, this.CmdTimeout, this.CmdParameters.ToArray());
+ public Task