Updating entities is a little bit different from adding and deleting in that there is no Update method in either the
DbContext or the
DbSet classes. You get the instance of the object you want to update, change its properties, and then invoke
SaveChanges. The following code demonstrates this:
Sub UpdateProduct() Try Dim check = northwindContext.Products. Single(Function(p) p. ProductName = "Italian spaghetti") check.Discontinued = True check.UnitsInStock = 30 northwindContext.SaveChanges() 'Product does not exist Catch ex As InvalidOperationException Catch ex As UpdateException End TryEnd Sub
Just remember to check ...