private async Task DealWithBatchAsync() { using (var scope = _serviceProvider.CreateScope()) using (var _context = (ProjectDbContext)scope.ServiceProvider.GetRequiredService(typeof(ProjectDbContext))) using (IRepository <TestModel> _repository = new DbContextRepository <TestModel>(_context)) { for (var i = 0; i < 1000; i++) { _repository.Add(_fixture.Build <TestModel>() .With(x => x.Id, 0) .With(x => x.Nested1TestModel, (_fixture.Build <Nested1TestModel>().With(x => x.Id, 0).Create())) .Create() ); } await _repository.SaveAsync(); // final save for items outside of the batch } Console.WriteLine("Worked on 1k"); }
public T Save(T cat) { entity.Add(cat); this.entity.SaveChanges(); return(cat); }