private async Task RunSaveChangesOnInsertAndUpdateAsync() { using var context = new TestContext(ContextUtil.GetOptions()); var loadedEntites = await context.Items.Include(a => a.ItemHistories).Where(a => a.ItemId <= 3000).ToListAsync(); // load first 3000 entities var existingEntites = loadedEntites.Where(a => a.ItemId <= 2000).ToList(); // take first 2000 of loaded entities and update them foreach (var existingEntity in existingEntites) { existingEntity.Description += " UPDATED"; existingEntity.ItemHistories.FirstOrDefault().Remark += " UPD"; } var newEntities = GetNewEntities(4000, "NEW "); await context.Items.AddRangeAsync(newEntities); await context.BulkSaveChangesAsync(); // Validate Test int entitiesCount = await context.Items.CountAsync(); Item firstEntity = await context.Items.SingleOrDefaultAsync(a => a.ItemId == 1); Assert.Equal(9000, entitiesCount); Assert.EndsWith(" UPDATED", firstEntity.Description); }
private async Task RunSaveChangesOnInsertAsync() { using var context = new TestContext(ContextUtil.GetOptions()); var newEntities = GetNewEntities(5000, ""); await context.Items.AddRangeAsync(newEntities); await context.BulkSaveChangesAsync(); // Validate Test int entitiesCount = await context.Items.CountAsync(); Item firstEntity = await context.Items.SingleOrDefaultAsync(a => a.ItemId == 1); Assert.Equal(5000, entitiesCount); Assert.Equal("Name 1", firstEntity.Name); }