本文整理汇总了C#中System.Data.DataRow.HasKeyChanged方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.HasKeyChanged方法的具体用法?C# DataRow.HasKeyChanged怎么用?C# DataRow.HasKeyChanged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataRow
的用法示例。
在下文中一共展示了DataRow.HasKeyChanged方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckConstraint
internal override void CheckConstraint(DataRow childRow, DataRowAction action) {
if ((action == DataRowAction.Change ||
action == DataRowAction.Add ||
action == DataRowAction.Rollback) &&
Table.DataSet != null && Table.DataSet.EnforceConstraints &&
childRow.HasKeyChanged(childKey)) {
// This branch is for cascading case verification.
DataRowVersion version = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
object[] childKeyValues = childRow.GetKeyValues(childKey);
// check to see if this is just a change to my parent's proposed value.
if (childRow.HasVersion(version)) {
// this is the new proposed value for the parent.
DataRow parentRow = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
if(parentRow != null && parentRow.inCascade) {
object[] parentKeyValues = parentRow.GetKeyValues(parentKey, action == DataRowAction.Rollback ? version : DataRowVersion.Default);
int parentKeyValuesRecord = childRow.Table.NewRecord();
childRow.Table.SetKeyValues(childKey, parentKeyValues, parentKeyValuesRecord);
if (childKey.RecordsEqual(childRow.tempRecord, parentKeyValuesRecord)) {
return;
}
}
}
// now check to see if someone exists... it will have to be in a parent row's current, not a proposed.
object[] childValues = childRow.GetKeyValues(childKey);
if (!IsKeyNull(childValues)) {
Index parentIndex = parentKey.GetSortIndex();
if (!parentIndex.IsKeyInIndex(childValues)) {
// could be self-join constraint
if (childKey.Table == parentKey.Table && childRow.tempRecord != -1) {
int lo = 0;
for (lo = 0; lo < childValues.Length; lo++) {
DataColumn column = parentKey.ColumnsReference[lo];
object value = column.ConvertValue(childValues[lo]);
if (0 != column.CompareValueTo(childRow.tempRecord, value)) {
break;
}
}
if (lo == childValues.Length) {
return;
}
}
throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, childKeyValues);
}
}
}
}
示例2: CheckCascade
internal void CheckCascade(DataRow row, DataRowAction action) {
Debug.Assert(Table.DataSet != null, "ForeignKeyConstraint " + ConstraintName + " isn't part of a DataSet, so this check shouldn't be happening.");
if (row.inCascade)
return;
row.inCascade = true;
try {
if (action == DataRowAction.Change) {
if (row.HasKeyChanged(parentKey)) {
CascadeUpdate(row);
}
}
else if (action == DataRowAction.Delete) {
CascadeDelete(row);
}
else if (action == DataRowAction.Commit) {
CascadeCommit(row);
}
else if (action == DataRowAction.Rollback) {
CascadeRollback(row);
}
else if (action == DataRowAction.Add) {
}
else {
Debug.Assert(false, "attempt to cascade unknown action: " + ((Enum) action).ToString());
}
}
finally {
row.inCascade = false;
}
}
示例3: CascadeRollback
internal void CascadeRollback(DataRow row) {
Index childIndex = childKey.GetSortIndex( row.RowState == DataRowState.Deleted ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);
object[] key = row.GetKeyValues(parentKey, row.RowState == DataRowState.Modified ? DataRowVersion.Current : DataRowVersion.Default );
//
if (IsKeyNull(key)) {
return;
}
Range range = childIndex.FindRecords(key);
if (acceptRejectRule == AcceptRejectRule.Cascade) {
if (!range.IsNull) {
DataRow[] rows = childIndex.GetRows(range);
for (int j = 0; j < rows.Length; j++) {
if (rows[j].inCascade)
continue;
rows[j].RejectChanges();
}
}
}
else {
// AcceptRejectRule.None
if (row.RowState != DataRowState.Deleted && row.Table.DataSet.EnforceConstraints) {
if (!range.IsNull) {
if (range.Count == 1 && childIndex.GetRow(range.Min) == row)
return;
if (row.HasKeyChanged(parentKey)) {// if key is not changed, this will not cause child to be stranded
throw ExceptionBuilder.FailedCascadeUpdate(ConstraintName);
}
}
}
}
}
示例4: CheckConstraint
internal override void CheckConstraint(DataRow childRow, DataRowAction action)
{
if (((((action == DataRowAction.Change) || (action == DataRowAction.Add)) || (action == DataRowAction.Rollback)) && ((this.Table.DataSet != null) && this.Table.DataSet.EnforceConstraints)) && childRow.HasKeyChanged(this.childKey))
{
DataRowVersion version = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
object[] keyValues = childRow.GetKeyValues(this.childKey);
if (childRow.HasVersion(version))
{
DataRow row = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
if ((row != null) && row.inCascade)
{
object[] objArray2 = row.GetKeyValues(this.parentKey, (action == DataRowAction.Rollback) ? version : DataRowVersion.Default);
int record = childRow.Table.NewRecord();
childRow.Table.SetKeyValues(this.childKey, objArray2, record);
if (this.childKey.RecordsEqual(childRow.tempRecord, record))
{
return;
}
}
}
object[] values = childRow.GetKeyValues(this.childKey);
if (!this.IsKeyNull(values) && !this.parentKey.GetSortIndex().IsKeyInIndex(values))
{
if ((this.childKey.Table == this.parentKey.Table) && (childRow.tempRecord != -1))
{
int index = 0;
index = 0;
while (index < values.Length)
{
DataColumn column = this.parentKey.ColumnsReference[index];
object obj2 = column.ConvertValue(values[index]);
if (column.CompareValueTo(childRow.tempRecord, obj2) != 0)
{
break;
}
index++;
}
if (index == values.Length)
{
return;
}
}
throw ExceptionBuilder.ForeignKeyViolation(this.ConstraintName, keyValues);
}
}
}
示例5: CheckCascade
internal void CheckCascade(DataRow row, DataRowAction action)
{
if (!row.inCascade)
{
row.inCascade = true;
try
{
if (action == DataRowAction.Change)
{
if (row.HasKeyChanged(this.parentKey))
{
this.CascadeUpdate(row);
}
}
else if (action == DataRowAction.Delete)
{
this.CascadeDelete(row);
}
else if (action == DataRowAction.Commit)
{
this.CascadeCommit(row);
}
else if (action == DataRowAction.Rollback)
{
this.CascadeRollback(row);
}
}
finally
{
row.inCascade = false;
}
}
}
示例6: CascadeRollback
internal void CascadeRollback(DataRow row)
{
Index sortIndex = this.childKey.GetSortIndex((row.RowState == DataRowState.Deleted) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);
object[] keyValues = row.GetKeyValues(this.parentKey, (row.RowState == DataRowState.Modified) ? DataRowVersion.Current : DataRowVersion.Default);
if (!this.IsKeyNull(keyValues))
{
Range range = sortIndex.FindRecords(keyValues);
if (this.acceptRejectRule == System.Data.AcceptRejectRule.Cascade)
{
if (!range.IsNull)
{
DataRow[] rows = sortIndex.GetRows(range);
for (int i = 0; i < rows.Length; i++)
{
if (!rows[i].inCascade)
{
rows[i].RejectChanges();
}
}
}
}
else if (((((row.RowState != DataRowState.Deleted) && row.Table.DataSet.EnforceConstraints) && !range.IsNull) && ((range.Count != 1) || (sortIndex.GetRow(range.Min) != row))) && row.HasKeyChanged(this.parentKey))
{
throw ExceptionBuilder.FailedCascadeUpdate(this.ConstraintName);
}
}
}