/// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationTypeAlias">Alias of the type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public IRelation Relate(IUmbracoEntity parent, IUmbracoEntity child, string relationTypeAlias)
        {
            var relationType = GetRelationTypeByAlias(relationTypeAlias);

            if (relationType == null || string.IsNullOrEmpty(relationType.Alias))
            {
                throw new ArgumentNullException(string.Format("No RelationType with Alias '{0}' exists.", relationTypeAlias));
            }

            var relation = new Relation(parent.Id, child.Id, relationType);

            if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs <IRelation>(relation), this))
            {
                return(relation);
            }

            var uow = UowProvider.GetUnitOfWork();

            using (var repository = RepositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();
            }

            SavedRelation.RaiseEvent(new SaveEventArgs <IRelation>(relation, false), this);
            return(relation);
        }
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationType">The type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public IRelation Relate(IUmbracoEntity parent, IUmbracoEntity child, IRelationType relationType)
        {
            //Ensure that the RelationType has an indentity before using it to relate two entities
            if (relationType.HasIdentity == false)
            {
                Save(relationType);
            }

            var relation = new Relation(parent.Id, child.Id, relationType);

            if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs <IRelation>(relation), this))
            {
                return(relation);
            }

            var uow = UowProvider.GetUnitOfWork();

            using (var repository = RepositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();
            }

            SavedRelation.RaiseEvent(new SaveEventArgs <IRelation>(relation, false), this);
            return(relation);
        }
        /// <summary>
        /// Saves a <see cref="Relation"/>
        /// </summary>
        /// <param name="relation">Relation to save</param>
        public void Save(IRelation relation)
        {
            if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs <IRelation>(relation), this))
            {
                return;
            }

            var uow = UowProvider.GetUnitOfWork();

            using (var repository = RepositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();
            }

            SavedRelation.RaiseEvent(new SaveEventArgs <IRelation>(relation, false), this);
        }