Exemple #1
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Removes this instance.
 /// </summary>
 ///-------------------------------------------------------------------------------------------------
 protected override void Remove()
 {
     using (var session = EnsuresRunInSession())
     {
         var cmd = new RemoveRelationshipCommand(this);
         Session.Current.Execute(cmd);
         if (session != null)
         {
             session.AcceptChanges();
         }
     }
 }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Removes the given item.
        /// </summary>
        /// <exception cref="ReadOnlyException">
        ///  Thrown when a Read Only error condition occurs.
        /// </exception>
        /// <param name="item">
        ///  The item to remove.
        /// </param>
        /// <returns>
        ///  true if it succeeds, false if it fails.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        protected bool RemoveInternal(T item)
        {
            if (IsReadOnly)
            {
                throw new ReadOnlyException();
            }

            if (null == item)
            {
                return(false);
            }

            var start = Source ?? item;
            var end   = End ?? item;
            var link  = start.GetRelationships(SchemaRelationship, end).FirstOrDefault();

            if (link == null)
            {
                return(false);
            }

            var cmd     = new RemoveRelationshipCommand(link);
            var session = EnsuresSession();

            try
            {
                Session.Current.Execute(cmd);
            }
            finally
            {
                if (session != null)
                {
                    session.AcceptChanges();
                    session.Dispose();
                }
            }
            //  Count--;
            return(true); // cmd.Success;
        }