/// <summary> /// Builds the and save. /// </summary> /// <returns></returns> protected async Task <T> PersistSelfAsync(IAsyncRepository repository) { var transactionalRepo = repository as ITransactional; if (transactionalRepo != null) { Debug.Assert(transactionalRepo.HasCurrenTransaction); } if (!AmIPersisted) { ApplicationContext.Logger.Log(LoggingLevel.Debug, "Builder", () => "Persisting {0}", typeof(T)); OnBeforePersistSelf(); await repository.CreateAsync(Target); await repository.SaveChangesAsync(); await repository.ClearAsync(); ApplicationContext.Logger.Log(LoggingLevel.Debug, "Builder", () => "Persisted {0} with Id: {1}", typeof(T), Target.Id); } else { ApplicationContext.Logger.Log(LoggingLevel.Debug, "Builder", () => "Skipping persist of {0} with id {1}", typeof(T), Target.Id); } return(Target); }