/// <summary>
        /// Writes all of the items in the changeset to the database.
        /// </summary>
        /// <returns></returns>
        public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            await EntityIndexWriter.ApplyIndexingAsync(cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            await EntityRelationshipWriter.CommitEntityRelationshipsAsync(ChangeTracker, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            ChangeTracker.DetectChanges();
            CheckEntityValidation();
            cancellationToken.ThrowIfCancellationRequested();
            await EntityWriter.WriteAsync(ChangeTracker, cancellationToken).ConfigureAwait(false);

            ChangeTracker.CommitChanges();
        }
        public async Task AddRelationshipToNewEntityAsync()
        {
            var connection = TestConfiguration.GetConnection();
            var entity     = new SingleEntityIntegrationModel
            {
                RelatedItem = new StringIdModel
                {
                    Description = "SaveNewEntity-RelatedItem"
                }
            };

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

            await entityRelationshipWriter.CommitEntityRelationshipsAsync(new[] { entity }).ConfigureAwait(false);

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