Search code examples
c#.netserializationdatasetdata-integrity

DataSet Serialization Problem in .Net


I have a dataset containing several tables, which is populated from a stored procedure. I want to make it nested for the GetXml() method.

I added the relation:

set.Relations.Add(
    new DataRelation("Author_Document",
        new DataColumn[] { set.Tables["Author"].Columns["lngDocumentSeriesId"], set.Tables["Author"].Columns["strAuthorName"] },
        new DataColumn[] { set.Tables["Document"].Columns["lngDocumentSeriesId"], set.Tables["Document"].Columns["strAuthorName"] }, true));

I made it nested:

foreach (DataRelation relation in set.Relations)
{
    relation.Nested = true;
}

And enforced:

set.EnforceConstraints = true;

All of which run fine, with no errors. The problem is when I call set.GetXml(), which throws a DataException: "Cannot proceed with serializing DataTable 'Document'. It contains a DataRow which has multiple parent rows on the same Foreign Key".

Upon inspection, the tables in question have each just a single row. The columns lngDocumentSeriesId and strAuthorName match. Even if there were a data integrety problem, it should have caused the exception on the set.EnforceConstraints = true; line, as I understand it.

What could cause this error (when all tables have just a single row), and how can it be fixed?


Solution

  • any other relations on the dataset ? ('there are two different tables that are each the parent, and each has one row')