I am having trouble deleting an entity -
Using db As Context = New Context
Dim car = db.Car.First(Function(x) x.ID = txtCarID.text)
db.Entry(car).State = Data.Entity.EntityState.Deleted
End Using
I have tried many other syntax, here is another -
Using db As Context = New Context
Dim car = new Car With {.ID = txtCarID.text}
db.Car.Attach(car)
db.Car.Remove(car)
End Using
I have received no errors but the record is never deleted.
Where am I going wrong?
Thanks,
silent_programmer
8682 gold badges10 silver badges21 bronze badges
1 Answer 1
You need to call SaveChanges method of DbContext after you made the changes. Otherwise changes will not be committed to databse.
answered Mar 22, 2015 at 6:20
Mohayemin
3,8704 gold badges29 silver badges55 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Dan
Wow... I knew that too but never connected the dots. Thank you for the quick reply, it is much appreciated!
default