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,

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.

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

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.