Exemplo n.º 1
0
        private async Task <int> _BulkUpdate(string tableName, DataTable dataTable, string[] whereColumns, string[] updateColumns)
        {
            var datas = new string[dataTable.Rows.Count].ToList();

            Begin(datas, false);
            Check.Exception(whereColumns == null || whereColumns.Count() == 0, "where columns count=0 or need primary key");
            Check.Exception(updateColumns == null || updateColumns.Count() == 0, "set columns count=0");
            var isAuto = this.context.CurrentConnectionConfig.IsAutoCloseConnection;

            this.context.CurrentConnectionConfig.IsAutoCloseConnection = false;
            dataTable.TableName = this.queryable.SqlBuilder.GetTranslationTableName(tableName);
            DataTable    dt     = GetCopyWriteDataTable(dataTable);
            IFastBuilder buider = GetBuider();

            buider.Context = context;
            await buider.CreateTempAsync <object>(dt);

            await buider.ExecuteBulkCopyAsync(dt);

            //var queryTemp = this.context.Queryable<T>().AS(dt.TableName).ToList();//test
            var result = await buider.UpdateByTempAsync(GetTableName(), dt.TableName, updateColumns, whereColumns);

            this.context.DbMaintenance.DropTable(dt.TableName);
            this.context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
            buider.CloseDb();
            End(datas, false);
            return(result);
        }
Exemplo n.º 2
0
        private async Task <int> _BulkUpdate(List <T> datas, string[] whereColumns, string[] updateColumns)
        {
            Begin(datas, false);
            Check.Exception(whereColumns == null || whereColumns.Count() == 0, "where columns count=0 or need primary key");
            Check.Exception(updateColumns == null || updateColumns.Count() == 0, "set columns count=0");
            var isAuto = this.context.CurrentConnectionConfig.IsAutoCloseConnection;

            this.context.CurrentConnectionConfig.IsAutoCloseConnection = false;
            DataTable    dt     = ToDdateTable(datas);
            IFastBuilder buider = GetBuider();

            buider.Context = context;
            await buider.CreateTempAsync <T>(dt);

            await buider.ExecuteBulkCopyAsync(dt);

            //var queryTemp = this.context.Queryable<T>().AS(dt.TableName).ToList();//test
            var result = await buider.UpdateByTempAsync(GetTableName(), dt.TableName, updateColumns, whereColumns);

            if (this.context.CurrentConnectionConfig.DbType != DbType.Sqlite)
            {
                this.context.DbMaintenance.DropTable(dt.TableName);
            }
            this.context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
            buider.CloseDb();
            End(datas, false);
            return(result);
        }