System.Data.DataRow.GetNestedParentRow C# (CSharp) Method

GetNestedParentRow() private method

private GetNestedParentRow ( DataRowVersion version ) : DataRow
version DataRowVersion
return DataRow
        internal DataRow GetNestedParentRow(DataRowVersion version)
        {
            // 1) Walk over all FKs and get the non-null. 2) Get the relation. 3) Get the parent Row.
            DataRelation[] nestedParentRelations = _table.NestedParentRelations;
            foreach (DataRelation rel in nestedParentRelations)
            {
                if (rel == null) // don't like this but done for backward code compatability
                {
                    continue;
                }
                if (rel.ParentTable == _table) // self-nested table
                {
                    CheckForLoops(rel);
                }

                DataRow row = GetParentRow(rel, version);
                if (row != null)
                {
                    return row;
                }
            }
            return null;// Rule 1: At all times, only ONE FK  "(in a row) can be non-Null
        }
        // No Nested in 1-many

Usage Example

Example #1
0
        private void GenerateRow(DataRow row) {
            DataRowState state = row.RowState;
            if ((state == DataRowState.Unchanged ) || (state  == DataRowState.Added)) {
                return;
            }
            if (!fBefore) {
                _xmlw.WriteStartElement( Keywords.DFF, Keywords.SQL_BEFORE, Keywords.DFFNS);
                fBefore = true;
            }

            DataTable table = row.Table;
            int colCount = table.Columns.Count;
            string rowIDString = table.TableName+row.rowID.ToString(CultureInfo.InvariantCulture);
            string parentId = null;
            if ( (state == DataRowState.Deleted )  && (row.Table.NestedParentRelations.Length != 0)){
                DataRow parentRow = row.GetNestedParentRow(DataRowVersion.Original);
                if (parentRow != null) {
                    parentId = parentRow.Table.TableName+parentRow.rowID.ToString(CultureInfo.InvariantCulture);
                }
            }


            string tablePrefix = (table.Namespace.Length != 0) ? table.Prefix : String.Empty;

            // read value if the TextOnly column (if any)
            object val = (table.XmlText == null ? DBNull.Value : row[table.XmlText, DataRowVersion.Original]);

                    //old row
            _xmlw.WriteStartElement( tablePrefix, row.Table.EncodedTableName, row.Table.Namespace);

            _xmlw.WriteAttributeString( Keywords.DFF, Keywords.DIFFID, Keywords.DFFNS, rowIDString);

            if ( (state == DataRowState.Deleted ) && XmlDataTreeWriter.RowHasErrors(row))
                _xmlw.WriteAttributeString( Keywords.DFF, Keywords.HASERRORS, Keywords.DFFNS, Keywords.TRUE);

            if (parentId != null)
                _xmlw.WriteAttributeString( Keywords.DFF, Keywords.DIFFPID, Keywords.DFFNS, parentId);

            _xmlw.WriteAttributeString( Keywords.MSD, Keywords.ROWORDER, Keywords.MSDNS, rowsOrder[row].ToString());
            for (int colNum = 0; colNum < colCount; ++colNum) {
                if ((row.Table.Columns[colNum].ColumnMapping == MappingType.Attribute) ||
                    (row.Table.Columns[colNum].ColumnMapping == MappingType.Hidden))
                GenerateColumn(row,  row.Table.Columns[colNum], DataRowVersion.Original);
            }
            for (int colNum = 0; colNum < colCount; ++colNum) {
                if ((row.Table.Columns[colNum].ColumnMapping == MappingType.Element) ||
                    (row.Table.Columns[colNum].ColumnMapping == MappingType.SimpleContent))
                GenerateColumn(row,  row.Table.Columns[colNum], DataRowVersion.Original);
            }
            _xmlw.WriteEndElement();  //old row
        }
All Usage Examples Of System.Data.DataRow::GetNestedParentRow