0

I can get all the records in a table i need:

 using (Entities db = new Entities())
                {
    db.PROJ_PLOFDataRecord.Where(x => x.Account_Id == 1);
}

I now want to remove them...cant i say something like .RemoveAll()

John
  • 3,965
  • 21
  • 77
  • 163
  • Possible duplicate question for http://stackoverflow.com/questions/2519866/how-do-i-delete-multiple-rows-in-entity-framework-without-foreach – failedprogramming Mar 13 '14 at 23:29

2 Answers2

0

Assuming you are in EF6, try

db.PROJ_PLOFDataRecord.Local.Clear();
db.SaveChanges();

You may need to call db.PROJ_PLOFDataRecord.Load() first to get the Local collection populated.

Here is the documentation for .Local (MSDN)

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
0

You can do this:

yourContext.Database
           .ExecuteSqlCommand("TRUNCATE TABLE <Table>");
Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
  • Yeah. If he has an anemic table with eithe no foreign keys or was not smart enough to set up foreign key relationships that may even work. Bad news is that this would in most cases be a sign of incompetence - or a REALLY rare table. With foreign keys that - fails. -1. – TomTom Mar 13 '14 at 23:34
  • @John, If you have FK why you want to remove all data from table? – Hamlet Hakobyan Mar 13 '14 at 23:37
  • +1 I actually think this is an interesting approach. The FK problem might even be ok if ON DELETE CASCADE was set during creation. – BradleyDotNET Mar 13 '14 at 23:41