本文整理汇总了C#中System.Data.DataRow.GetKeyValues方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.GetKeyValues方法的具体用法?C# DataRow.GetKeyValues怎么用?C# DataRow.GetKeyValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataRow
的用法示例。
在下文中一共展示了DataRow.GetKeyValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public bool Invoke(DataRow row, DataRowVersion version) {
object[] parentValues = GetParentValues();
if (parentValues == null) {
return false;
}
object[] childValues = row.GetKeyValues(childKey, version);
#if false
for (int i = 0; i < keyValues.Length; i++) {
Debug.WriteLine("keyvalues[" + (i).ToString() + "] = " + Convert.ToString(keyValues[i]));
}
for (int i = 0; i < values.Length; i++) {
Debug.WriteLine("values[" + (i).ToString() + "] = " + Convert.ToString(values[i]));
}
#endif
bool allow = true;
if (childValues.Length != parentValues.Length) {
allow = false;
}
else {
for (int i = 0; i < childValues.Length; i++) {
if (!childValues[i].Equals(parentValues[i])) {
allow = false;
break;
}
}
}
IFilter baseFilter = base.GetFilter();
if (baseFilter != null) {
allow &= baseFilter.Invoke(row, version);
}
return allow;
}
示例2: Invoke
public bool Invoke(DataRow row, DataRowVersion version)
{
object[] parentValues = GetParentValues();
if (parentValues == null)
{
return false;
}
object[] childValues = row.GetKeyValues(_childKey, version);
bool allow = true;
if (childValues.Length != parentValues.Length)
{
allow = false;
}
else
{
for (int i = 0; i < childValues.Length; i++)
{
if (!childValues[i].Equals(parentValues[i]))
{
allow = false;
break;
}
}
}
IFilter baseFilter = base.GetFilter();
if (baseFilter != null)
{
allow &= baseFilter.Invoke(row, version);
}
return allow;
}
示例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: CascadeCommit
internal void CascadeCommit(DataRow row) {
if (row.RowState == DataRowState.Detached)
return;
if (acceptRejectRule == AcceptRejectRule.Cascade) {
Index childIndex = childKey.GetSortIndex( row.RowState == DataRowState.Deleted ? DataViewRowState.Deleted : DataViewRowState.CurrentRows );
object[] key = row.GetKeyValues(parentKey, row.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Default );
if (IsKeyNull(key)) {
return;
}
Range range = childIndex.FindRecords(key);
if (!range.IsNull) {
// SQLBU 499726 - DataTable internal index is corrupted: '13'
// Self-referencing table has suspendIndexEvents, in the multi-table scenario the child table hasn't
// this allows the self-ref table to maintain the index while in the child-table doesn't
DataRow[] rows = childIndex.GetRows(range);
foreach(DataRow childRow in rows) {
if (DataRowState.Detached != childRow.RowState) {
if (childRow.inCascade)
continue;
childRow.AcceptChanges();
}
}
}
}
}
示例5: SetParentRow
/// <summary>
/// Sets current row's parent row with specified relation.
/// </summary>
public void SetParentRow(DataRow parentRow, DataRelation relation)
{
if (relation == null)
{
SetParentRow(parentRow);
return;
}
if (parentRow == null)
{
SetParentRowToDBNull(relation);
return;
}
if (_table.DataSet != parentRow._table.DataSet)
{
throw ExceptionBuilder.ParentRowNotInTheDataSet();
}
if (relation.ChildKey.Table != _table)
{
throw ExceptionBuilder.SetParentRowTableMismatch(relation.ChildKey.Table.TableName, _table.TableName);
}
if (relation.ParentKey.Table != parentRow._table)
{
throw ExceptionBuilder.SetParentRowTableMismatch(relation.ParentKey.Table.TableName, parentRow._table.TableName);
}
object[] parentKeyValues = parentRow.GetKeyValues(relation.ParentKey);
SetKeyValues(relation.ChildKey, parentKeyValues);
}
示例6: SetNestedParentRow
internal void SetNestedParentRow(DataRow parentRow, bool setNonNested)
{
if (parentRow == null)
{
SetParentRowToDBNull();
return;
}
foreach (DataRelation relation in _table.ParentRelations)
{
if (relation.Nested || setNonNested)
{
if (relation.ParentKey.Table == parentRow._table)
{
object[] parentKeyValues = parentRow.GetKeyValues(relation.ParentKey);
SetKeyValues(relation.ChildKey, parentKeyValues);
if (relation.Nested)
{
if (parentRow._table == _table)
{
CheckForLoops(relation);
}
else
{
GetParentRow(relation);
}
}
}
}
}
}
示例7: SetParentRowRecords
internal void SetParentRowRecords(DataRow childRow, DataRow parentRow) {
object[] parentKeyValues = parentRow.GetKeyValues(ParentKey);
if (childRow.tempRecord != -1) {
ChildTable.recordManager.SetKeyValues(childRow.tempRecord, ChildKey, parentKeyValues);
}
if (childRow.newRecord != -1) {
ChildTable.recordManager.SetKeyValues(childRow.newRecord, ChildKey, parentKeyValues);
}
if (childRow.oldRecord != -1) {
ChildTable.recordManager.SetKeyValues(childRow.oldRecord, ChildKey, parentKeyValues);
}
}
示例8: CascadeDelete
internal void CascadeDelete(DataRow row)
{
if (-1 != row.newRecord)
{
object[] keyValues = row.GetKeyValues(this.parentKey, DataRowVersion.Current);
if (!this.IsKeyNull(keyValues))
{
Index sortIndex = this.childKey.GetSortIndex();
switch (this.DeleteRule)
{
case Rule.None:
if (row.Table.DataSet.EnforceConstraints)
{
Range range4 = sortIndex.FindRecords(keyValues);
if (range4.IsNull)
{
return;
}
if ((range4.Count != 1) || (sortIndex.GetRow(range4.Min) != row))
{
throw ExceptionBuilder.FailedCascadeDelete(this.ConstraintName);
}
}
return;
case Rule.Cascade:
{
object[] key = row.GetKeyValues(this.parentKey, DataRowVersion.Default);
Range range3 = sortIndex.FindRecords(key);
if (!range3.IsNull)
{
foreach (DataRow row2 in sortIndex.GetRows(range3))
{
if (!row2.inCascade)
{
row2.Table.DeleteRow(row2);
}
}
}
return;
}
case Rule.SetNull:
{
object[] objArray3 = new object[this.childKey.ColumnsReference.Length];
for (int i = 0; i < this.childKey.ColumnsReference.Length; i++)
{
objArray3[i] = DBNull.Value;
}
Range range2 = sortIndex.FindRecords(keyValues);
if (!range2.IsNull)
{
DataRow[] rows = sortIndex.GetRows(range2);
for (int j = 0; j < rows.Length; j++)
{
if (row != rows[j])
{
rows[j].SetKeyValues(this.childKey, objArray3);
}
}
}
return;
}
case Rule.SetDefault:
{
object[] objArray2 = new object[this.childKey.ColumnsReference.Length];
for (int k = 0; k < this.childKey.ColumnsReference.Length; k++)
{
objArray2[k] = this.childKey.ColumnsReference[k].DefaultValue;
}
Range range = sortIndex.FindRecords(keyValues);
if (!range.IsNull)
{
DataRow[] rowArray = sortIndex.GetRows(range);
for (int m = 0; m < rowArray.Length; m++)
{
if (row != rowArray[m])
{
rowArray[m].SetKeyValues(this.childKey, objArray2);
}
}
}
return;
}
}
}
}
}
示例9: GetParentRows
/// <devdoc>
/// Gets the parent rows for the given child row across the relation using the version given
/// </devdoc>
internal static DataRow[] GetParentRows(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) {
object[] values = childRow.GetKeyValues(childKey, version);
if (IsKeyNull(values)) {
return parentKey.Table.NewRowArray(0);
}
Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);
return index.GetRows(values);
}
示例10: SetNestedParentRow
internal void SetNestedParentRow(DataRow parentRow, bool setNonNested)
{
if (parentRow == null)
{
this.SetParentRowToDBNull();
}
else
{
foreach (DataRelation relation in this._table.ParentRelations)
{
if ((relation.Nested || setNonNested) && (relation.ParentKey.Table == parentRow._table))
{
object[] keyValues = parentRow.GetKeyValues(relation.ParentKey);
this.SetKeyValues(relation.ChildKey, keyValues);
if (relation.Nested)
{
if (parentRow._table == this._table)
{
this.CheckForLoops(relation);
}
else
{
this.GetParentRow(relation);
}
}
}
}
}
}
示例11: CascadeCommit
internal void CascadeCommit(DataRow row)
{
if ((row.RowState != DataRowState.Detached) && (this.acceptRejectRule == System.Data.AcceptRejectRule.Cascade))
{
Index sortIndex = this.childKey.GetSortIndex((row.RowState == DataRowState.Deleted) ? DataViewRowState.Deleted : DataViewRowState.CurrentRows);
object[] keyValues = row.GetKeyValues(this.parentKey, (row.RowState == DataRowState.Deleted) ? DataRowVersion.Original : DataRowVersion.Default);
if (!this.IsKeyNull(keyValues))
{
Range range = sortIndex.FindRecords(keyValues);
if (!range.IsNull)
{
foreach (DataRow row2 in sortIndex.GetRows(range))
{
if ((DataRowState.Detached != row2.RowState) && !row2.inCascade)
{
row2.AcceptChanges();
}
}
}
}
}
}
示例12: 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);
}
}
}
示例13: CascadeUpdate
internal void CascadeUpdate(DataRow row)
{
if (-1 != row.newRecord)
{
object[] keyValues = row.GetKeyValues(this.parentKey, DataRowVersion.Current);
if (this.Table.DataSet.fInReadXml || !this.IsKeyNull(keyValues))
{
Index sortIndex = this.childKey.GetSortIndex();
switch (this.UpdateRule)
{
case Rule.None:
if (row.Table.DataSet.EnforceConstraints && !sortIndex.FindRecords(keyValues).IsNull)
{
throw ExceptionBuilder.FailedCascadeUpdate(this.ConstraintName);
}
return;
case Rule.Cascade:
{
Range range3 = sortIndex.FindRecords(keyValues);
if (!range3.IsNull)
{
object[] objArray4 = row.GetKeyValues(this.parentKey, DataRowVersion.Proposed);
DataRow[] rows = sortIndex.GetRows(range3);
for (int i = 0; i < rows.Length; i++)
{
rows[i].SetKeyValues(this.childKey, objArray4);
}
}
return;
}
case Rule.SetNull:
{
object[] objArray3 = new object[this.childKey.ColumnsReference.Length];
for (int j = 0; j < this.childKey.ColumnsReference.Length; j++)
{
objArray3[j] = DBNull.Value;
}
Range range2 = sortIndex.FindRecords(keyValues);
if (!range2.IsNull)
{
DataRow[] rowArray2 = sortIndex.GetRows(range2);
for (int k = 0; k < rowArray2.Length; k++)
{
rowArray2[k].SetKeyValues(this.childKey, objArray3);
}
}
return;
}
case Rule.SetDefault:
{
object[] objArray2 = new object[this.childKey.ColumnsReference.Length];
for (int m = 0; m < this.childKey.ColumnsReference.Length; m++)
{
objArray2[m] = this.childKey.ColumnsReference[m].DefaultValue;
}
Range range = sortIndex.FindRecords(keyValues);
if (!range.IsNull)
{
DataRow[] rowArray = sortIndex.GetRows(range);
for (int n = 0; n < rowArray.Length; n++)
{
rowArray[n].SetKeyValues(this.childKey, objArray2);
}
}
return;
}
}
}
}
}
示例14: 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);
}
}
}
示例15: CascadeUpdate
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;
}
}
}