Subscribe to our YouTube Channel for more Videos

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");
Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.