Greg
Greg

Reputation: 2690

How to delete a db row in LINQPAD

Total NOOB question. I have been using the new linqpad for about 20 minutes now. Great!

But now i want to delete a row in the db. I am using a EF5.0 connection. I cant seem to find anything in the help files or on the net. The only thing I can find is DeleteOnSubmit which doesnt work with EF (as far as I can see). I have also tried DeleteObject which doesnt work either. This is what I have tried.

var co = Companies.First();
co.Dump();

Companies.DeleteObject(co);

Upvotes: 11

Views: 8960

Answers (2)

azarc3
azarc3

Reputation: 1306

This is old... and I don't know if/when this was added (probably in response to this exact scenario)… but you can accomplish this (in your given example) as follows:

//test the following line to ensure the context doesn't complain about the .First() reference

Companies.DeleteOnSubmit(Companies.First()); 

Companies.Context.SubmitChanges();

Upvotes: 15

David Hoerster
David Hoerster

Reputation: 28701

You need to SaveChanges on your context (Companies) for your row to be deleted.

Companies.SaveChanges();

Upvotes: 3

Related Questions