///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  An IHyperstore extension method that creates a relationship.
        /// </summary>
        /// <exception cref="SessionRequiredException">
        ///  Thrown when a Session Required error condition occurs.
        /// </exception>
        /// <typeparam name="T">
        ///  Generic type parameter.
        /// </typeparam>
        /// <param name="store">
        ///  The store to act on.
        /// </param>
        /// <param name="start">
        ///  The start.
        /// </param>
        /// <param name="end">
        ///  The end.
        /// </param>
        /// <param name="id">
        ///  (Optional) the identifier.
        /// </param>
        /// <returns>
        ///  The new relationship.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public static T CreateRelationship <T>(this IHyperstore store, IModelElement start, IModelElement end, Identity id = null) where T : IModelRelationship
        {
            Contract.Requires(store != null, "store");
            Contract.Requires(start != null, "start");
            Contract.Requires(end != null, "end");

            if (Session.Current == null)
            {
                throw new SessionRequiredException();
            }
            var domain = start.DomainModel;
            var schema = store.GetSchemaRelationship <T>();
            var cmd    = new AddRelationshipCommand(schema, start, end, id);

            Session.Current.Execute(cmd);
            return((T)cmd.Relationship);
        }
예제 #2
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Gets the relationships.
 /// </summary>
 /// <typeparam name="T">
 ///  Generic type parameter.
 /// </typeparam>
 /// <param name="end">
 ///  (Optional)
 /// </param>
 /// <returns>
 ///  An enumerator that allows foreach to be used to process the relationships in this collection.
 /// </returns>
 ///-------------------------------------------------------------------------------------------------
 public IEnumerable <T> GetRelationships <T>(IModelElement end = null) where T : IModelRelationship
 {
     return(GetRelationships(_store.GetSchemaRelationship <T>(), end)
            .Select(rel => (T)rel));
 }