10

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);
Greg
  • 2,654
  • 3
  • 36
  • 59
  • Shouldn't this be just `DeleteObject(co)` and then `SaveChanges()` ? – sgmoore Sep 09 '13 at 12:02
  • @sgmoore - see the error below. I found another way to delete rows in the database because I don't have time to waste on this. I created a new connection directly to the database. My original effort was trying to delete entities through the context but I have not been able to get that to work. – Greg Sep 09 '13 at 17:39
  • 1
    You can only get that error if you use Companies.DeleteObject(co). The error should not occur if you call just call DeleteObject(co) (or this.DeleteObject(co) if you prefer). – sgmoore Sep 09 '13 at 18:36

2 Answers2

15

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();
azarc3
  • 1,277
  • 13
  • 21
3

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

Companies.SaveChanges();

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
  • This error is being thrown:Cannot execute text selection: 'System.Data.Entity.DbSet' does not contain a definition for 'DeleteObject' and no extension method 'DeleteObject' accepting a first argument of type 'System.Data.Entity.DbSet' could be found (press F4 to add a using directive or assembly reference) – Greg Sep 07 '13 at 13:31
  • 1
    .. and linqpad doesn't explicitly expose the context. – Greg Sep 07 '13 at 13:38