Fixes for broken RO check
[mono.git] / mcs / class / System.Data / System.Data / MergeManager.cs
index af4fd7e40735c9207f415f1f4e83c488e6a185ae..911ca37f36fc848b535b135ee0a7c7f5fbcbf6ab 100644 (file)
@@ -37,6 +37,8 @@ namespace System.Data
                                throw new ArgumentNullException("targetSet");
                        if(sourceSet == null)
                                throw new ArgumentNullException("sourceSet");
+                       if (sourceSet == targetSet)
+                               return;
 
                        bool prevEC = targetSet.EnforceConstraints;
                        targetSet.EnforceConstraints = false;
@@ -54,6 +56,8 @@ namespace System.Data
                                throw new ArgumentNullException("targetSet");
                        if(sourceTable == null)
                                throw new ArgumentNullException("sourceTable");
+                       if (sourceTable.DataSet == targetSet)
+                               return;
 
                        bool savedEnfoceConstraints = targetSet.EnforceConstraints;
                        targetSet.EnforceConstraints = false;
@@ -75,6 +79,8 @@ namespace System.Data
                                throw new ArgumentNullException("targetTable");
                        if(sourceTable == null)
                                throw new ArgumentNullException("sourceTable");
+                       if (sourceTable == targetTable)
+                               return;
 
                        bool savedEnforceConstraints = targetTable.EnforceConstraints;
                        targetTable.EnforceConstraints = false;
@@ -116,7 +122,6 @@ namespace System.Data
                // merge a row into a target table.
                private static void MergeRow(DataTable targetTable, DataRow row, bool preserveChanges)
                {
-                       DataColumnCollection columns = row.Table.Columns;
                        DataColumn[] primaryKeys = targetTable.PrimaryKey;
                        DataRow targetRow = null;
                        DataRowVersion version = DataRowVersion.Default;
@@ -143,7 +148,8 @@ namespace System.Data
                        if (targetRow == null)
                        { 
                                DataRow newRow = targetTable.NewNotInitializedRow();
-                               row.CopyValuesToRow(newRow);
+                               // Don't check for ReadOnly, when cloning data to new uninitialized row.
+                               row.CopyValuesToRow(newRow, false);
                                targetTable.Rows.AddInternal (newRow);
                        }
                        // row exists in target table, and presere changes is false - 
@@ -223,7 +229,7 @@ namespace System.Data
                                        DataColumn[] childColumns = ResolveColumns (targetSet.Tables [relation.ChildTable.TableName],
                                                        relation.ChildColumns);
                                        targetRelation = targetSet.Relations.Add (relation.RelationName, parentColumns,
-                                                       childColumns, false);
+                                                       childColumns, relation.createConstraints);
                                        targetRelation.Nested = relation.Nested;
                                } else if (!CompareColumnArrays (relation.ParentColumns, targetRelation.ParentColumns) ||
                                                !CompareColumnArrays (relation.ChildColumns, targetRelation.ChildColumns)) {