internal void CascadeUpdate(DataRow row)
{
if (-1 == row._newRecord)
{
return;
}
object[] currentKey = row.GetKeyValues(_parentKey, DataRowVersion.Current);
if (!Table.DataSet._fInReadXml && IsKeyNull(currentKey))
{
return;
}
Index childIndex = _childKey.GetSortIndex();
switch (UpdateRule)
{
case Rule.None:
{
if (row.Table.DataSet.EnforceConstraints)
{
// if we're not cascading deletes, we should throw if we're going to strand a child row under enforceConstraints.
Range range = childIndex.FindRecords(currentKey);
if (!range.IsNull)
{
throw ExceptionBuilder.FailedCascadeUpdate(ConstraintName);
}
}
break;
}
case Rule.Cascade:
{
Range range = childIndex.FindRecords(currentKey);
if (!range.IsNull)
{
object[] proposedKey = row.GetKeyValues(_parentKey, DataRowVersion.Proposed);
DataRow[] rows = childIndex.GetRows(range);
for (int j = 0; j < rows.Length; j++)
{
// if (rows[j].inCascade)
// continue;
rows[j].SetKeyValues(_childKey, proposedKey);
}
}
break;
}
case Rule.SetNull:
{
object[] proposedKey = new object[_childKey.ColumnsReference.Length];
for (int i = 0; i < _childKey.ColumnsReference.Length; i++)
proposedKey[i] = DBNull.Value;
Range range = childIndex.FindRecords(currentKey);
if (!range.IsNull)
{
DataRow[] rows = childIndex.GetRows(range);
for (int j = 0; j < rows.Length; j++)
{
// if (rows[j].inCascade)
// continue;
rows[j].SetKeyValues(_childKey, proposedKey);
}
}
break;
}
case Rule.SetDefault:
{
object[] proposedKey = new object[_childKey.ColumnsReference.Length];
for (int i = 0; i < _childKey.ColumnsReference.Length; i++)
proposedKey[i] = _childKey.ColumnsReference[i].DefaultValue;
Range range = childIndex.FindRecords(currentKey);
if (!range.IsNull)
{
DataRow[] rows = childIndex.GetRows(range);
for (int j = 0; j < rows.Length; j++)
{
// if (rows[j].inCascade)
// continue;
rows[j].SetKeyValues(_childKey, proposedKey);
}
}
break;
}
default:
{
Debug.Assert(false, "Unknown Rule value");
break;
}
}
}