private void MergeTable(DataTable src, DataTable dst) { int rowsCount = src.Rows.Count; bool wasEmpty = dst.Rows.Count == 0; if (0 < rowsCount) { Index? ndxSearch = null; DataKey key = default(DataKey); dst.SuspendIndexEvents(); try { if (!wasEmpty && dst._primaryKey != null) { key = GetSrcKey(src, dst); if (key.HasValue) { ndxSearch = dst._primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } // this improves performance by iterating over the rows instead of computing their position foreach (DataRow sourceRow in src.Rows) { DataRow?targetRow = null; if (ndxSearch != null) { targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch); } dst.MergeRow(sourceRow, targetRow, _preserveChanges, ndxSearch); } } finally { dst.RestoreIndexEvents(true); } } MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
private void MergeTable(DataTable src, DataTable dst) { int count = src.Rows.Count; bool flag = dst.Rows.Count == 0; if (0 < count) { Index ndx = null; DataKey srcKey = new DataKey(); dst.SuspendIndexEvents(); try { if (!flag && (dst.primaryKey != null)) { srcKey = this.GetSrcKey(src, dst); if (srcKey.HasValue) { ndx = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } foreach (DataRow row2 in src.Rows) { DataRow targetRow = null; if (ndx != null) { targetRow = dst.FindMergeTarget(row2, srcKey, ndx); } dst.MergeRow(row2, targetRow, this.preserveChanges, ndx); } } finally { dst.RestoreIndexEvents(true); } } this.MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
private void MergeTable(DataTable src, DataTable dst) { int rowsCount = src.Rows.Count; bool wasEmpty = dst.Rows.Count == 0; if(0 < rowsCount) { Index ndxSearch = null; DataKey key = default(DataKey); dst.SuspendIndexEvents(); try { if(! wasEmpty && dst.primaryKey != null) { key = GetSrcKey(src, dst); if (key.HasValue) ndxSearch = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added ); } // SQLBU 414992: Serious performance issue when calling Merge // this improves performance by iterating over the rows instead of computing their position foreach(DataRow sourceRow in src.Rows) { DataRow targetRow = null; if(ndxSearch != null) { targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch); } dst.MergeRow(sourceRow, targetRow, preserveChanges, ndxSearch); } } finally { dst.RestoreIndexEvents(true); } } MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }