34

I'm using EF5 in VS2012, and I trying to delete all data of some table using ExecuteStoreCommand, something like this:

ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]");

but the problem is EF is telling me, method ExecuteStoreCommand not found. I can't understand why?

Can you tell me why?, or give me a performant solution remove all data of the table.

SteveC
  • 15,808
  • 23
  • 102
  • 173
qakmak
  • 1,287
  • 9
  • 31
  • 62

1 Answers1

91

Try this:

ctx.Database.ExecuteSqlCommand
Justin Harvey
  • 14,446
  • 2
  • 27
  • 30
  • 1
    This answer should be mark as answer...this is a perfect solution.1 vote up for you @Justin Harvey – Kashif Hanif Dec 11 '13 at 08:45
  • 2
    i am using : ctx.Database.ExecuteSqlCommand("SET IDENTITY_INSERT profile ON") But its not working... Unable to insert custom primary key. How to do that ? – Er Mayank Apr 16 '15 at 07:44