///------------------------------------------------------------------------------------------------- /// <summary> /// An IHyperstore extension method that creates an entity. /// </summary> /// <exception cref="SessionRequiredException"> /// Thrown when a Session Required error condition occurs. /// </exception> /// <param name="domain"> /// the domain model. /// </param> /// <param name="schema"> /// The schema. /// </param> /// <param name="id"> /// (Optional) the identifier. /// </param> /// <returns> /// The new entity. /// </returns> ///------------------------------------------------------------------------------------------------- public static IModelEntity CreateEntity(this IDomainModel domain, ISchemaEntity schema, Identity id = null) { Contract.Requires(domain != null, "domain"); Contract.Requires(schema != null, "schema"); if (Session.Current == null) { throw new SessionRequiredException(); } var cmd = new AddEntityCommand(domain, schema, id); Session.Current.Execute(cmd); return(cmd.Entity); }
///------------------------------------------------------------------------------------------------- /// <summary> /// An IDomainModel extension method that creates a relationship. /// </summary> /// <exception cref="SessionRequiredException"> /// Thrown when a Session Required error condition occurs. /// </exception> /// <param name="domain"> /// the domain model. /// </param> /// <param name="schema"> /// The schema. /// </param> /// <param name="startId"> /// The start identifier. /// </param> /// <param name="endId"> /// The end identifier. /// </param> /// <param name="id"> /// (Optional) the identifier. /// </param> /// <returns> /// The new relationship. /// </returns> ///------------------------------------------------------------------------------------------------- public static IModelRelationship CreateRelationship(this IDomainModel domain, ISchemaRelationship schema, Identity startId, Identity endId, Identity id = null) { Contract.Requires(domain != null, "domain"); Contract.Requires(schema != null, "schema"); Contract.Requires(startId != null, "startId"); Contract.Requires(endId != null, "endId"); if (Session.Current == null) { throw new SessionRequiredException(); } var start = domain.GetElement(startId); if (start == null) { throw new InvalidElementException(startId); } var cmd = new AddRelationshipCommand(schema, start, endId, id); Session.Current.Execute(cmd); return(cmd.Relationship); }