internal override bool IsConstraintViolated() { Index childIndex = childKey.GetSortIndex(); object[] uniqueChildKeys = childIndex.GetUniqueKeyValues(); bool errors = false; Index parentIndex = parentKey.GetSortIndex(); for (int i = 0; i < uniqueChildKeys.Length; i++) { object[] childValues = (object[])uniqueChildKeys[i]; if (!IsKeyNull(childValues)) { if (!parentIndex.IsKeyInIndex(childValues)) { DataRow[] rows = childIndex.GetRows(childIndex.FindRecords(childValues)); string error = Res.GetString(Res.DataConstraint_ForeignKeyViolation, ConstraintName, ExceptionBuilder.KeysToString(childValues)); for (int j = 0; j < rows.Length; j++) { rows[j].RowError = error; } errors = true; } } } return(errors); }
internal override bool CanEnableConstraint() { if (Table.EnforceConstraints) { return(key.GetSortIndex().CheckUnique()); } return(true); }
internal static DataRow?GetParentRow(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) { if (!childRow.HasVersion((version == DataRowVersion.Original) ? DataRowVersion.Original : DataRowVersion.Current)) { if (childRow._tempRecord == -1) { return(null); } } object[] values = childRow.GetKeyValues(childKey, version); if (IsKeyNull(values)) { return(null); } Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows); Range range = index.FindRecords(values); if (range.IsNull) { return(null); } if (range.Count > 1) { throw ExceptionBuilder.MultipleParents(); } return(parentKey.Table._recordManager[index.GetRecord(range.Min)]); }
internal static DataRow[] GetParentRows(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) { object[] keyValues = childRow.GetKeyValues(childKey, version); if (IsKeyNull(keyValues)) { return(parentKey.Table.NewRowArray(0)); } return(parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows).GetRows(keyValues)); }
internal void ConstraintIndexInitialize() { if (null == _constraintIndex) { _constraintIndex = _key.GetSortIndex(); _constraintIndex.AddRef(); } AssertConstraintAndKeyIndexes(); }
internal void ConstraintIndexInitialize() { //Debug.Assert(null == _constraintIndex, "non-null UniqueConstraint index"); if (null == _constraintIndex) { _constraintIndex = key.GetSortIndex(); _constraintIndex.AddRef(); } AssertConstraintAndKeyIndexes(); }
/// <include file='doc\DataRelation.uex' path='docs/doc[@for="DataRelation.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(); return(index.GetRows(values)); }
/// <include file='doc\ConstraintCollection.uex' path='docs/doc[@for="ConstraintCollection.Remove"]/*' /> /// <devdoc> /// <para> /// Removes the specified <see cref='System.Data.Constraint'/> /// from the collection.</para> /// </devdoc> public void Remove(Constraint constraint) { if (constraint == null) { throw ExceptionBuilder.ArgumentNull("constraint"); } // this will throw an exception if it can't be removed, otherwise indicates // whether we need to remove it from the collection. if (CanRemove(constraint, true)) { // constraint can be removed BaseRemove(constraint); ArrayRemove(constraint); if (constraint is UniqueConstraint && ((UniqueConstraint)constraint).IsPrimaryKey) { Table.PrimaryKey = null; } if (constraint is UniqueConstraint) { for (int i = 0; i < Table.ChildRelations.Count; i++) { DataRelation rel = Table.ChildRelations[i]; if (rel.ParentKeyConstraint == constraint) { rel.SetParentKeyConstraint(null); } } DataKey key = ((UniqueConstraint)constraint).Key; key.GetSortIndex().RemoveRef(); } else if (constraint is ForeignKeyConstraint) { for (int i = 0; i < Table.ParentRelations.Count; i++) { DataRelation rel = Table.ParentRelations[i]; if (rel.ChildKeyConstraint == constraint) { rel.SetChildKeyConstraint(null); } } } OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, constraint)); } }
internal static DataRow GetParentRow(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) { if (!childRow.HasVersion((version == DataRowVersion.Original) ? DataRowVersion.Original : DataRowVersion.Current)) if (childRow.tempRecord == -1) return null; object[] values = childRow.GetKeyValues(childKey, version); if (IsKeyNull(values)) { return null; } Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows); Range range = index.FindRecords(values); if (range.IsNull) { return null; } if (range.Count > 1) { throw ExceptionBuilder.MultipleParents(); } return parentKey.Table.recordManager[index.GetRecord(range.Min)]; }
/// <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); }
internal static DataRow[] GetChildRows(DataKey parentKey, DataKey childKey, DataRow parentRow, DataRowVersion version) { object[] keyValues = parentRow.GetKeyValues(parentKey, version); if (IsKeyNull(keyValues)) { return childKey.Table.NewRowArray(0); } return childKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows).GetRows(keyValues); }