2
How to delete all data from a database table using EF6 without having to query (I want to delete all records)?
2
How to delete all data from a database table using EF6 without having to query (I want to delete all records)?
5
The simplest way is:
context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Tabela]");
Yes, this does not go directly through the Entity Framework. To explicitly use the Entity Framework, it is best to implement an extension:
public static void ApagarTudo<T>(this DbSet<T> dbSet) where T : class
{
dbSet.RemoveRange(dbSet);
}
Use:
contexto.Entidades.ApagarTudo();
contexto.SaveChanges();
1
You can use the Executestorequery() method of your context by passing an SQL command to delete all records, see the example below.
seuContexto.ExecuteStoreQuery("delete SuaTabela");
For more details visit the link below https://msdn.microsoft.com/pt-br/library/vstudio/dd487208(v=vs.100). aspx
Browser other questions tagged c# entity-framework
You are not signed in. Login or sign up in order to post.