/// <summary>
        /// Updates an InMemoryVertex
        /// </summary>
        /// <param name="toBeUpdatedVertex">The vertex that should be updated</param>
        /// <param name="myVertexUpdate">The definition of the vertex update</param>
        /// <returns>The updated vertex</returns>
        private InMemoryVertex UpdateVertex_private(InMemoryVertex toBeUpdatedVertex,
                                                    VertexUpdateDefinition myVertexUpdate)
        {
            #region udpate comment

            if (myVertexUpdate.CommentUpdate != null)
            {
                toBeUpdatedVertex.UpdateComment(myVertexUpdate.CommentUpdate);
            }

            #endregion

            #region update binary properties

            if (myVertexUpdate.UpdatedBinaryProperties != null)
            {
                toBeUpdatedVertex.UpdateBinaryProperties(myVertexUpdate.UpdatedBinaryProperties.Updated,
                                                         myVertexUpdate.UpdatedBinaryProperties.Deleted);
            }

            #endregion

            #region udpate single edges

            if (myVertexUpdate.UpdatedSingleEdges != null)
            {
                if (toBeUpdatedVertex.OutgoingEdges == null)
                {
                    lock (toBeUpdatedVertex)
                    {
                        toBeUpdatedVertex.OutgoingEdges = new Dictionary<long, IEdge>();
                    }
                }

                lock (toBeUpdatedVertex.OutgoingEdges)
                {

                    #region delete edges

                    if (myVertexUpdate.UpdatedSingleEdges.Deleted != null)
                    {
                        foreach (var item in myVertexUpdate.UpdatedSingleEdges.Deleted)
                        {
                            IEdge edge = null;

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item, out edge))
                            {
                                if (edge is SingleEdge)
                                {
                                    var targetVertex = edge.GetTargetVertices().First();

                                    RemoveIncommingEdgeFromTargetVertex((InMemoryVertex)targetVertex, targetVertex.VertexTypeID, item, toBeUpdatedVertex);

                                    toBeUpdatedVertex.OutgoingEdges.Remove(item);
                                }
                            }
                        }
                    }

                    #endregion

                    #region update edges

                    if (myVertexUpdate.UpdatedSingleEdges.Updated != null)
                    {
                        foreach (var item in myVertexUpdate.UpdatedSingleEdges.Updated)
                        {
                            IEdge edge = null;
                            var targetVertex = GetOrCreateTargetVertex(item.Value.TargetVertex.VertexTypeID, item.Value.TargetVertex.VertexID);

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item.Key, out edge))
                            {
                                if (edge is SingleEdge)
                                {
                                    var singleEdge = (SingleEdge)edge;

                                    if (edge.Comment != null)
                                    {
                                        singleEdge.UpdateComment(item.Value.CommentUpdate);
                                    }

                                    if (item.Value.EdgeTypeID != null)
                                    {
                                        singleEdge.UpdateEdgeType(item.Value.EdgeTypeID);
                                    }

                                    if (item.Value.UpdatedStructuredProperties != null)
                                    {
                                        singleEdge.UpdateStructuredProperties(
                                        item.Value.UpdatedStructuredProperties.Updated,
                                        item.Value.UpdatedStructuredProperties.Deleted);
                                    }

                                    if (item.Value.UpdatedUnstructuredProperties != null)
                                    {
                                        singleEdge.UpdateUnStructuredProperties(
                                        item.Value.UpdatedUnstructuredProperties.Updated,
                                        item.Value.UpdatedUnstructuredProperties.Deleted);
                                    }

                                    if (item.Value.SourceVertex != null)
                                    {
                                        lock (singleEdge)
                                        {
                                            singleEdge.SourceVertex = toBeUpdatedVertex;
                                        }
                                    }

                                    if (item.Value.TargetVertex != null)
                                    {
                                        lock (singleEdge)
                                        {
                                            if (singleEdge.TargetVertex != null)
                                            {
                                                RemoveIncommingEdgeFromTargetVertex(singleEdge.TargetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                            }

                                            singleEdge.TargetVertex = targetVertex;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                edge = new SingleEdge(item.Value.EdgeTypeID,
                                                      toBeUpdatedVertex,
                                                      targetVertex,
                                                      item.Value.CommentUpdate, 0, 0,
                                                      item.Value.UpdatedStructuredProperties == null ? null : item.Value.UpdatedStructuredProperties.Updated, item.Value.UpdatedUnstructuredProperties == null ? null : item.Value.UpdatedUnstructuredProperties.Updated);

                                toBeUpdatedVertex.OutgoingEdges.Add(item.Key, edge);
                            }

                            CreateOrUpdateIncomingEdgesOnVertex(targetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                        }
                    }

                    #endregion
                }
            }

            #endregion

            #region update hyper edges

            if (myVertexUpdate.UpdateHyperEdges != null)
            {
                if (toBeUpdatedVertex.OutgoingEdges == null)
                {
                    lock (toBeUpdatedVertex)
                    {
                        toBeUpdatedVertex.OutgoingEdges = new Dictionary<long, IEdge>();
                    }
                }

                lock (toBeUpdatedVertex.OutgoingEdges)
                {
                    #region delete edges


                    if (myVertexUpdate.UpdateHyperEdges.Deleted != null)
                    {
                        foreach (var item in myVertexUpdate.UpdateHyperEdges.Deleted)
                        {
                            IEdge edge = null;

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item, out edge))
                            {
                                if (edge is HyperEdge)
                                {
                                    foreach (var targetVertex in edge.GetTargetVertices())
                                    {
                                        RemoveIncommingEdgeFromTargetVertex((InMemoryVertex)targetVertex, targetVertex.VertexTypeID, item, toBeUpdatedVertex);
                                    }

                                    toBeUpdatedVertex.OutgoingEdges.Remove(item);
                                }
                            }
                        }
                    }

                    #endregion

                    #region update edges

                    if (myVertexUpdate.UpdateHyperEdges.Updated != null)
                    {
                        foreach (var item in myVertexUpdate.UpdateHyperEdges.Updated)
                        {
                            IEdge edge = null;

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item.Key, out edge))
                            {
                                if (edge is HyperEdge)
                                {
                                    var hyperEdge = (HyperEdge)edge;

                                    if (edge.Comment != null)
                                    {
                                        hyperEdge.UpdateComment(item.Value.CommentUpdate);
                                    }

                                    if (item.Value.EdgeTypeID != null)
                                    {
                                        hyperEdge.UpdateEdgeType(item.Value.EdgeTypeID);
                                    }

                                    if (item.Value.UpdatedUnstructuredProperties != null)
                                        hyperEdge.UpdateUnStructuredProperties(
                                            item.Value.UpdatedUnstructuredProperties.Updated,
                                            item.Value.UpdatedUnstructuredProperties.Deleted);

                                    if (item.Value.UpdatedStructuredProperties != null)
                                        hyperEdge.UpdateStructuredProperties(
                                            item.Value.UpdatedStructuredProperties.Updated,
                                            item.Value.UpdatedStructuredProperties.Deleted);

                                    #region update the containing single edges

                                    lock (hyperEdge.ContainedSingleEdges)
                                    {
                                        if (item.Value.ToBeDeletedSingleEdges != null)
                                        {
                                            foreach (var singleEdge in item.Value.ToBeDeletedSingleEdges)
                                            {
                                                var targetVertex = GetOrCreateTargetVertex(singleEdge.TargetVertex.VertexTypeID, singleEdge.TargetVertex.VertexID);
                                                RemoveIncommingEdgeFromTargetVertex(targetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                                hyperEdge.ContainedSingleEdges.RemoveWhere(sEdge => (sEdge.SourceVertex.VertexTypeID == singleEdge.SourceVertex.VertexTypeID && sEdge.SourceVertex.VertexID == singleEdge.SourceVertex.VertexID) && (sEdge.TargetVertex.VertexID == singleEdge.TargetVertex.VertexID && sEdge.TargetVertex.VertexTypeID == singleEdge.TargetVertex.VertexTypeID));
                                            }
                                        }

                                        if (item.Value.ToBeUpdatedSingleEdges != null)
                                        {
                                            var newEdges = new List<SingleEdge>();

                                            foreach (var contEdge in item.Value.ToBeUpdatedSingleEdges)
                                            {
                                                var targetVertex =
                                                    GetOrCreateTargetVertex(contEdge.TargetVertex.VertexTypeID,
                                                                            contEdge.TargetVertex.VertexID);

                                                foreach (var singleEdgeItem in hyperEdge.ContainedSingleEdges)
                                                {
                                                    var correspondTarget =
                                                        GetOrCreateTargetVertex(contEdge.TargetVertex.VertexTypeID,
                                                                                contEdge.TargetVertex.VertexID);

                                                    var correspondSource =
                                                        GetOrCreateTargetVertex(contEdge.SourceVertex.VertexTypeID,
                                                                                contEdge.SourceVertex.VertexID);

                                                    if (correspondTarget == singleEdgeItem.TargetVertex &&
                                                        singleEdgeItem.SourceVertex == correspondSource)
                                                    {
                                                        if (contEdge.CommentUpdate != null)
                                                        {
                                                            singleEdgeItem.UpdateComment(contEdge.CommentUpdate);
                                                        }

                                                        if (contEdge.EdgeTypeID != null)
                                                        {
                                                            singleEdgeItem.UpdateEdgeType(contEdge.EdgeTypeID);
                                                        }

                                                        if (contEdge.UpdatedStructuredProperties != null)
                                                        {
                                                            singleEdgeItem.UpdateStructuredProperties(
                                                                contEdge.UpdatedStructuredProperties.Updated,
                                                                contEdge.UpdatedStructuredProperties.Deleted);
                                                        }

                                                        if (contEdge.UpdatedUnstructuredProperties != null)
                                                        {
                                                            singleEdgeItem.UpdateUnStructuredProperties(
                                                                contEdge.UpdatedUnstructuredProperties.Updated,
                                                                contEdge.UpdatedUnstructuredProperties.Deleted);
                                                        }

                                                        if (contEdge.TargetVertex != null)
                                                        {
                                                            lock (singleEdgeItem)
                                                            {
                                                                if (singleEdgeItem.TargetVertex != null)
                                                                {
                                                                    RemoveIncommingEdgeFromTargetVertex(singleEdgeItem.TargetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                                                }

                                                                singleEdgeItem.TargetVertex = targetVertex;
                                                            }
                                                        }

                                                        if (contEdge.SourceVertex != null)
                                                        {
                                                            lock (singleEdgeItem)
                                                            {
                                                                singleEdgeItem.SourceVertex =
                                                                    GetOrCreateTargetVertex(
                                                                        contEdge.SourceVertex.VertexTypeID,
                                                                        contEdge.SourceVertex.VertexID);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        newEdges.Add(new SingleEdge(contEdge.EdgeTypeID,
                                                                                    toBeUpdatedVertex,
                                                                                    GetOrCreateTargetVertex(
                                                                                        contEdge.TargetVertex.
                                                                                            VertexTypeID,
                                                                                        contEdge.TargetVertex.VertexID),
                                                                                    contEdge.CommentUpdate, 0, 0,
                                                                                    contEdge.UpdatedStructuredProperties ==
                                                                                    null
                                                                                        ? null
                                                                                        : contEdge.
                                                                                              UpdatedStructuredProperties
                                                                                              .
                                                                                              Updated,
                                                                                    contEdge.
                                                                                        UpdatedUnstructuredProperties ==
                                                                                    null
                                                                                        ? null
                                                                                        : contEdge.
                                                                                              UpdatedUnstructuredProperties
                                                                                              .
                                                                                              Updated));
                                                    }
                                                }

                                                CreateOrUpdateIncomingEdgesOnVertex(targetVertex,
                                                                                    toBeUpdatedVertex.VertexTypeID,
                                                                                    item.Key, toBeUpdatedVertex);
                                                hyperEdge.ContainedSingleEdges.UnionWith(newEdges);
                                                newEdges.Clear();
                                            }
                                        }
                                    }

                                    #endregion
                                }
                            }
                            else
                            {

                                var singleEdges = new HashSet<SingleEdge>();

                                if (item.Value.ToBeUpdatedSingleEdges != null)
                                {
                                    foreach (var singleItem in item.Value.ToBeUpdatedSingleEdges)
                                    {
                                        var targetVertex = GetOrCreateTargetVertex(singleItem.TargetVertex.VertexTypeID, singleItem.TargetVertex.VertexID);

                                        singleEdges.Add(new SingleEdge(singleItem.EdgeTypeID, toBeUpdatedVertex, targetVertex,
                                                                       singleItem.CommentUpdate == null ? null : singleItem.CommentUpdate, 0, 0,
                                                                       singleItem.UpdatedStructuredProperties == null
                                                                           ? null
                                                                           : singleItem.UpdatedStructuredProperties.
                                                                                 Updated,
                                                                       singleItem.UpdatedUnstructuredProperties == null
                                                                           ? null
                                                                           : singleItem.UpdatedUnstructuredProperties.
                                                                                 Updated));

                                        CreateOrUpdateIncomingEdgesOnVertex(targetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                    }

                                    toBeUpdatedVertex.OutgoingEdges.Add(item.Key,
                                                                        new HyperEdge(singleEdges,
                                                                                      item.Value.EdgeTypeID,
                                                                                      toBeUpdatedVertex,
                                                                                      item.Value.CommentUpdate == null ? null : item.Value.CommentUpdate,
                                                                                      0, 0,
                                                                                      item.Value.UpdatedStructuredProperties == null ? null : item.Value.UpdatedStructuredProperties.Updated,
                                                                                          item.Value.UpdatedUnstructuredProperties == null ? null : item.Value.UpdatedUnstructuredProperties.Updated));

                                }
                            }

                        }
                    }

                    #endregion
                }
            }

            #endregion

            #region update unstructured properties

            if (myVertexUpdate.UpdatedUnstructuredProperties != null)
            {
                toBeUpdatedVertex.UpdateUnstructuredProperties(myVertexUpdate.UpdatedUnstructuredProperties);
            }

            #endregion

            #region update structured properties

            if (myVertexUpdate.UpdatedStructuredProperties != null)
            {
                toBeUpdatedVertex.UpdateStructuredProperties(myVertexUpdate.UpdatedStructuredProperties);
            }

            #endregion

            return toBeUpdatedVertex;
        }
        private void AddEdgesToVertex(VertexAddDefinition myVertexDefinition, 
                                        InMemoryVertex myVertex, 
                                        Dictionary<Int64, IEdge> myEdges)
        {
            SingleEdge singleEdge;
            InMemoryVertex targetVertex;

            #region single edges

            //create the single edges

            if (myVertexDefinition.OutgoingSingleEdges != null)
            {
                foreach (var aSingleEdgeDefinition in myVertexDefinition.OutgoingSingleEdges)
                {
                    targetVertex =
                        GetOrCreateTargetVertex(aSingleEdgeDefinition.TargetVertexInformation.VertexTypeID,
                                                aSingleEdgeDefinition.TargetVertexInformation.VertexID);

                    //create the new Edge
                    singleEdge = new SingleEdge(aSingleEdgeDefinition.EdgeTypeID, 
                                                myVertex, 
                                                targetVertex,
                                                aSingleEdgeDefinition.Comment, 
                                                aSingleEdgeDefinition.CreationDate,
                                                aSingleEdgeDefinition.ModificationDate,
                                                aSingleEdgeDefinition.StructuredProperties,
                                                aSingleEdgeDefinition.UnstructuredProperties);

                    CreateOrUpdateIncomingEdgesOnVertex(
                        targetVertex,
                        myVertexDefinition.VertexTypeID,
                        aSingleEdgeDefinition.PropertyID,
                        myVertex);

                    myEdges.Add(aSingleEdgeDefinition.PropertyID, singleEdge);
                }
            }

            #endregion

            #region hyper edges

            if (myVertexDefinition.OutgoingHyperEdges != null)
            {
                foreach (var aHyperEdgeDefinition in myVertexDefinition.OutgoingHyperEdges)
                {
                    var containedSingleEdges = new HashSet<SingleEdge>();

                    foreach (var aSingleEdgeDefinition in aHyperEdgeDefinition.ContainedSingleEdges)
                    {
                        targetVertex =
                            GetOrCreateTargetVertex(aSingleEdgeDefinition.TargetVertexInformation.VertexTypeID,
                                                    aSingleEdgeDefinition.TargetVertexInformation.VertexID);

                        singleEdge = new SingleEdge(aSingleEdgeDefinition.EdgeTypeID, 
                                                    myVertex, 
                                                    targetVertex,
                                                    aSingleEdgeDefinition.Comment,
                                                    aSingleEdgeDefinition.CreationDate,
                                                    aSingleEdgeDefinition.ModificationDate,
                                                    aSingleEdgeDefinition.StructuredProperties,
                                                    aSingleEdgeDefinition.UnstructuredProperties);

                        CreateOrUpdateIncomingEdgesOnVertex(
                            targetVertex,
                            myVertexDefinition.VertexTypeID,
                            aHyperEdgeDefinition.PropertyID,
                            myVertex);

                        containedSingleEdges.Add(singleEdge);
                    }

                    //create the new edge
                    myEdges.Add(
                        aHyperEdgeDefinition.PropertyID,
                        new HyperEdge(
                            containedSingleEdges,
                            aHyperEdgeDefinition.EdgeTypeID,
                            myVertex,
                            aHyperEdgeDefinition.Comment,
                            aHyperEdgeDefinition.CreationDate,
                            aHyperEdgeDefinition.ModificationDate,
                            aHyperEdgeDefinition.StructuredProperties,
                            aHyperEdgeDefinition.UnstructuredProperties));

                }
            }

            #endregion

        }