public void DeleteAll(Func <T, bool> func) { var listToDelete = _prandoDbContext.Set <T>().Where(func); Array.ForEach(listToDelete.ToArray(), p => { if (typeof(T) == typeof(SoftDeletable)) { var detedableEntity = p as SoftDeletable; detedableEntity.IsDeleted = true; _prandoDbContext.Update(detedableEntity); } else { _prandoDbContext.Remove(p); } }); }
public async Task Can_add_update_delete_end_to_end_using_partial_shadow_state() { IMutableModel model = new Model(InMemoryConventionSetBuilder.Build()); var customerType = model.AddEntityType(typeof(Customer)); customerType.AddProperty("Name", typeof(string)); var optionsBuilder = new DbContextOptionsBuilder() .UseModel(model.FinalizeModel()) .UseInMemoryDatabase(nameof(ShadowStateUpdateTest)) .UseInternalServiceProvider(_fixture.ServiceProvider); var customer = new Customer { Id = 42 }; using (var context = new DbContext(optionsBuilder.Options)) { context.Add(customer); context.Entry(customer).Property("Name").CurrentValue = "Daenerys"; await context.SaveChangesAsync(); context.Entry(customer).Property("Name").CurrentValue = "Changed!"; } using (var context = new DbContext(optionsBuilder.Options)) { var customerFromStore = context.Set <Customer>().Single(); Assert.Equal(42, customerFromStore.Id); Assert.Equal( "Daenerys", (string)context.Entry(customerFromStore).Property("Name").CurrentValue); } using (var context = new DbContext(optionsBuilder.Options)) { var customerEntry = context.Entry(customer).GetInfrastructure(); customerEntry[customerType.FindProperty("Name")] = "Daenerys Targaryen"; context.Update(customer); await context.SaveChangesAsync(); } using (var context = new DbContext(optionsBuilder.Options)) { var customerFromStore = context.Set <Customer>().Single(); Assert.Equal(42, customerFromStore.Id); Assert.Equal( "Daenerys Targaryen", (string)context.Entry(customerFromStore).Property("Name").CurrentValue); } using (var context = new DbContext(optionsBuilder.Options)) { context.Remove(customer); await context.SaveChangesAsync(); } using (var context = new DbContext(optionsBuilder.Options)) { Assert.Equal(0, context.Set <Customer>().Count()); } }