System.Data.ConstraintCollection.Remove C# (CSharp) Метод

Remove() публичный Метод

Removes the specified from the collection.
public Remove ( Constraint constraint ) : void
constraint Constraint
Результат void
        public void Remove(Constraint constraint)
        {
            if (constraint == null)
                throw ExceptionBuilder.ArgumentNull(nameof(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;
                }

                OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, constraint));
            }
        }

Same methods

ConstraintCollection::Remove ( string name ) : void

Usage Example

Пример #1
0
        public virtual void Reset()
        {
            // first we remove all ForeignKeyConstraints (if we will not do that
            // we will get an exception when clearing the tables).
            for (int i = 0; i < Tables.Count; i++)
            {
                ConstraintCollection cc = Tables[i].Constraints;
                for (int j = 0; j < cc.Count; j++)
                {
                    if (cc[j] is ForeignKeyConstraint)
                    {
                        cc.Remove(cc[j]);
                    }
                }
            }

            Clear();
            Relations.Clear();
            Tables.Clear();
        }