public void test4() { var ProductToRemove = _context.Product .OrderBy(p => p.ProductId).First(); _context.Remove(ProductToRemove); Assert.Equal(EntityState.Deleted, _context.Entry(ProductToRemove).State); Product productToRemove2 = TestHelpers.CreateProduct("1"); productToRemove2.ProductId = 3; _context.Remove(productToRemove2); Assert.Equal(EntityState.Deleted, _context.Entry(productToRemove2).State); }
public void Test4() { var productToRemove = _context.Product.OrderBy(p => p.ProductId) .First(); _context.Remove(productToRemove); Assert.Equal(EntityState.Deleted, _context.Entry(productToRemove).State); Assert.Single(_context.ChangeTracker.Entries()); }
public void ShouldTrackRemovedRecords() { var productToRemove = _context.Product.OrderBy(p => p.ProductId).First(); _context.Product.Remove(productToRemove); Assert.Equal(EntityState.Deleted, _context.Entry(productToRemove).State); //again you can remove straight from the context var productToRemove2 = _context.Product.OrderBy(p => p.ProductId).Skip(1).First(); _context.Remove(productToRemove2); Assert.Equal(EntityState.Deleted, _context.Entry(productToRemove2).State); var productToRemove3 = TestHelpers.CreateProduct("3"); productToRemove3.ProductId = 3; _context.Product.Remove(productToRemove3); Assert.Equal(EntityState.Deleted, _context.Entry(productToRemove3).State); }
internal void DeleteProductUsingState(int productId, string name) { var prod = _context.ChangeTracker.Entries <Product>() .FirstOrDefault(p => p.Entity.ProductId == productId); if (prod != null) { prod.State = EntityState.Deleted; } else { var prodToDelete = new Product { ProductId = productId, Name = name }; _context.Remove(prodToDelete); } _context.SaveChanges(); }