Ejemplo n.º 1
0
        /// <summary>
        /// Remove an object from the list. For 1:n relations, if the object is persisted it will also
        /// be removed from the database. For n:m relations, the relation object is removed (the object
        /// being removed is left untouched and must manually be removed if so desired).
        /// </summary>
        /// <param name="transaction">The transaction within which to execute statements.</param>
        /// <param name="value">The object to remove from the list</param>
        public virtual void Remove(Transaction transaction, object value)
        {
            object val = Find(Key.GetKey(broker, false, value));

            value = val ?? value;
            if (Contains(value))
            {
                Check.VerifyNotNull(value, Error.NullParameter, "value");
                Check.Verify(containedMap.Type.Equals(value.GetType()) ||
                             value.GetType().IsSubclassOf(containedMap.Type),
                             Error.UnsupportedType, value.GetType());
                // call remove even if contains was false to make sure error reporting is unchanged
                // Note: calling ArrayList/base class RemoveAt seems to work but calling Remove does
                // not - calling base.Remove ends up here again - must be a bug in net-1.1.
                base.RemoveAt(IndexOf(value));
                if (viaInstances == null)
                {
                    // manage removed object
                    IPersistent obj = value as IPersistent;
                    if (obj.IsPersisted)
                    {
                        if (transaction != null)
                        {
                            transaction.Remove(obj);
                        }
                        else
                        {
                            obj.Remove();
                        }
                    }
                }
                else
                {
                    // manage n:m relation object
                    viaInstances.Remove(transaction, value);
                }
            }
        }