How to Delete all data from the table (Truncate) in Entity Framework ?

If you want to Truncate Data or delete all the data from the table in Entity Framework (.NET 4.5) , you can use the ExecuteSqlCommand defined in the DBContext.Database class .

How to Delete all data from the table(Truncate) in Entity Framework ?

Below is a sample source to demonstrate how to truncate table in Entity Framework.

dbContext.Database.ExecuteSqlCommand("TRUNCATE TABLE tablename");
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

Remove All Objects matching the condition from a List using LINQ in C#
Are you using LINQ in C# and requite to remove all objects matching the condition from a List ? Read...
Difference between DELETE and TRUNCATE command in SQL Server
Below are few points that differentiate the DELETE and TRUNCATE command.Sl. No.DELE...
Tiles in Windows Phone Mango - Create and Delete Secondary Tile
This is the 4th part of my series on the Tiles in Windows Phone Mango .In this Blog post , i wil...