- 增加 IInsert/IUpdate BatchOptions 方法指定批量插入的设置;

This commit is contained in:
28810
2019-12-20 19:47:43 +08:00
parent 80133d0af7
commit ab1d0a2cb5
27 changed files with 148 additions and 191 deletions

View File

@ -23,6 +23,8 @@ namespace FreeSql.Internal.CommonProvider
protected TableInfo _table;
protected Func<string, string> _tableRule;
protected bool _noneParameter, _insertIdentity;
protected int _batchValuesLimit, _batchParameterLimit;
protected bool _batchAutoTransaction = true;
protected DbParameter[] _params;
protected DbTransaction _transaction;
protected DbConnection _connection;
@ -50,6 +52,8 @@ namespace FreeSql.Internal.CommonProvider
}
protected void ClearData()
{
_batchValuesLimit = _batchParameterLimit = 0;
_batchAutoTransaction = true;
_insertIdentity = false;
_source.Clear();
_ignore.Clear();
@ -83,6 +87,14 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
public IInsert<T1> BatchOptions(int valuesLimit, int parameterLimit, bool autoTransaction = true)
{
_batchValuesLimit = valuesLimit;
_batchParameterLimit = parameterLimit;
_batchAutoTransaction = autoTransaction;
return this;
}
public IInsert<T1> AppendData(T1 source)
{
if (source != null)
@ -181,7 +193,7 @@ namespace FreeSql.Internal.CommonProvider
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
if (_transaction != null)
if (_transaction != null || _batchAutoTransaction == false)
{
for (var a = 0; a < ss.Length; a++)
{
@ -233,7 +245,7 @@ namespace FreeSql.Internal.CommonProvider
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
if (_transaction != null)
if (_transaction != null || _batchAutoTransaction == false)
{
for (var a = 0; a < ss.Length; a++)
{
@ -287,7 +299,7 @@ namespace FreeSql.Internal.CommonProvider
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
if (_transaction != null)
if (_transaction != null || _batchAutoTransaction == false)
{
for (var a = 0; a < ss.Length; a++)
{

View File

@ -30,6 +30,8 @@ namespace FreeSql.Internal.CommonProvider
protected List<DbParameter> _params = new List<DbParameter>();
protected List<DbParameter> _paramsSource = new List<DbParameter>();
protected bool _noneParameter;
protected int _batchRowsLimit, _batchParameterLimit;
protected bool _batchAutoTransaction = true;
protected DbTransaction _transaction;
protected DbConnection _connection;
@ -58,6 +60,8 @@ namespace FreeSql.Internal.CommonProvider
}
protected void ClearData()
{
_batchRowsLimit = _batchParameterLimit = 0;
_batchAutoTransaction = true;
_source.Clear();
_ignore.Clear();
_auditValueChangedDict.Clear();
@ -89,6 +93,14 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
public IUpdate<T1> BatchOptions(int rowsLimit, int parameterLimit, bool autoTransaction = true)
{
_batchRowsLimit = rowsLimit;
_batchParameterLimit = parameterLimit;
_batchAutoTransaction = autoTransaction;
return this;
}
protected void ValidateVersionAndThrow(int affrows)
{
if (_table.VersionColumn != null && _source.Count > 0)
@ -136,7 +148,7 @@ namespace FreeSql.Internal.CommonProvider
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
if (_transaction != null)
if (_transaction != null || _batchAutoTransaction == false)
{
for (var a = 0; a < ss.Length; a++)
{
@ -183,7 +195,7 @@ namespace FreeSql.Internal.CommonProvider
if (_transaction == null)
this.WithTransaction(_orm.Ado.TransactionCurrentThread);
if (_transaction != null)
if (_transaction != null || _batchAutoTransaction == false)
{
for (var a = 0; a < ss.Length; a++)
{