Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

How I can quickly remove all rows in table using Entity Framework?

I am currently using:

var rows = from o in dataDb.Table

           select o;

foreach (var row in rows)





However, it takes a long time to execute.

Are there any alternatives?

1 Answer

0 votes
by (40.4k points)

In Entity_Framework5 and Entity_Framework6 you can delete all rows in table this way:

Assuming context is a System.Data.Entity.DbContext

context.Database.ExecuteSqlCommand("TRUNCATE TABLE[TableName]");

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories