0

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
asked Mar 22, 2015 at 6:17

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Wow... I knew that too but never connected the dots. Thank you for the quick reply, it is much appreciated!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.