/// <summary>
 /// Writes all of the items in the changeset to the database.
 /// </summary>
 /// <returns></returns>
 public virtual void SaveChanges()
 {
     EntityIndexWriter.ApplyIndexing();
     EntityRelationshipWriter.CommitEntityRelationships(ChangeTracker);
     ChangeTracker.DetectChanges();
     CheckEntityValidation();
     EntityWriter.Write(ChangeTracker);
     ChangeTracker.CommitChanges();
 }
        public void AddRelationshipToNewEntity()
        {
            var connection = TestConfiguration.GetConnection();
            var entity     = new SingleEntityIntegrationModel
            {
                RelatedItem = new StringIdModel
                {
                    Description = "SaveNewEntity-RelatedItem"
                }
            };

            var entityRelationshipWriter = new EntityRelationshipWriter <SingleEntityIntegrationModel>(connection);

            entityRelationshipWriter.CommitEntityRelationships(new[] { entity });

            Assert.IsNotNull(entity.RelatedItemId);
            Assert.IsTrue(entity.RelatedItemId == entity.RelatedItem.Id);
        }