[Mono-bugs] [Bug 650398] New: Nested relation FKs not populated correctly on xml deserialization, with ColumnMapping=MappingType.Hidden

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Oct 31 15:19:37 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=650398

https://bugzilla.novell.com/show_bug.cgi?id=650398#c0


           Summary: Nested relation FKs not populated correctly on xml
                    deserialization, with ColumnMapping=MappingType.Hidden
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cvolzke at live.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5

Nested relation FKs not populated correctly on xml deserialization.
The foreign keys must be ColumnMapping=MappingType.Hidden for the bug to
reproduce, because the child FK value is set to the parent PK value.


Reproducible: Always

Steps to Reproduce:
Test case to reproduce:

        [Test]
        public void Test_SerializeDeserializeNestedDataSet()
        {
            DataSet data = NewDataSet();
            data.Tables[0].Rows.Add("key1", "");
            data.Tables[1].Rows.Add("key2", "key1");
            data.Tables[2].Rows.Add("", "key2");

            string xml = WriteXml(data);
            DataSet deserializedData = NewDataSet();
            deserializedData.ReadXml(new StringReader(xml));
            string deserializedXml = WriteXml(deserializedData);
            Assert.AreEqual(xml, deserializedXml);
        }

        static string WriteXml(DataSet data)
        {
            StringWriter writer = new StringWriter();
            data.WriteXml(writer);
            return writer.GetStringBuilder().ToString();
        }

        static DataSet NewDataSet()
        {
            DataTable table1 = new DataTable();
            DataColumn pk1 = table1.Columns.Add("PK");
            DataColumn fk1 = table1.Columns.Add("FK");
            fk1.ColumnMapping = MappingType.Hidden;

            DataTable table2 = new DataTable();
            DataColumn pk2 = table2.Columns.Add("PK");
            DataColumn fk2 = table2.Columns.Add("FK");
            fk2.ColumnMapping = MappingType.Hidden;

            DataTable table3 = new DataTable();
            DataColumn pk3 = table3.Columns.Add("PK");
            DataColumn fk3 = table3.Columns.Add("FK");
            fk3.ColumnMapping = MappingType.Hidden;

            DataSet data = new DataSet();
            data.Tables.Add(table1);
            data.Tables.Add(table2);
            data.Tables.Add(table3);
            data.Relations.Add(new DataRelation("r1", pk1, fk2) { Nested = true
});
            data.Relations.Add(new DataRelation("r2", pk2, fk3) { Nested = true
});
            return data;
        }

Actual Results:  
table1.FK and table2.FK are not populated.

The sequence of steps taken to deserialize are:
1. table1 deserialized
2. table1.FK = table2.PK (but table2.PK hasn't been deserialized yet!)
3. table2 deserialized
4. table2.FK = table3.PK (but table3.PK hasn't been deserialized yet!)
5. table3 deserialized

The code that populates the FK is in XmlDataReader.ReadElementElement.


Expected Results:  
The FKs should be populated by following this sequence of steps:

1. table1 deserialized
2. table1.FK = table2.PK (but table2.PK hasn't been deserialized yet!)
3. table2.FK = table3.PK (but table3.PK hasn't been deserialized yet!)
4. table2 deserialized
5. table3 deserialized


Proposed fix (not necessary best or optimised):

XmlDataReader (new field)
-------------------------
List<Action> nestedFKSetters = new List<Action>();

XmlDataReader.ReadElementElement
--------------------------------
:
:
DataRow childRow = rel.ChildTable.NewRow ();
ReadElement (childRow);

nestedFKSetters.Add(delegate {                 // LINE ADDED
    for (int c = 0; c < rel.ChildColumns.Length; c++) {
        childRow [rel.ChildColumns [c]]
            = row [rel.ParentColumns [c]];
    }
});                                            // LINE ADDED
:
:

XmlDataReader.Process
---------------------
:
:
    else
        ReadTopLevelElement ();
    foreach (Action action in nestedFKSetters)  // LINE ADDED
        action();                               // LINE ADDED
    } finally {
        dataset.EnforceConstraints = 
             savedEnforceConstraints;
    }
:
:

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list