Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 24, 2012 08:51 PM by CodeHobo
Contributor
2777 Points
1161 Posts
Feb 24, 2012 08:35 PM|LINK
foreach ( LogErrors log in GetAll() ) db.LogErrors.Remove( log ); db.SaveChanges();
All-Star
18669 Points
2648 Posts
Feb 24, 2012 08:51 PM|LINK
If you want to use straight linq, I believe you have to do them one at a time like you have above.
Have you tried using inline sql? this is faster
db.Database.ExecuteSqlCommand("Truncate table LogErrors");
eric2820
Contributor
2777 Points
1161 Posts
Using LINQ is this the best way to clear a table?
Feb 24, 2012 08:35 PM|LINK
foreach ( LogErrors log in GetAll() )
db.LogErrors.Remove( log );
db.SaveChanges();
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
CodeHobo
All-Star
18669 Points
2648 Posts
Re: Using LINQ is this the best way to clear a table?
Feb 24, 2012 08:51 PM|LINK
If you want to use straight linq, I believe you have to do them one at a time like you have above.
Have you tried using inline sql? this is faster
db.Database.ExecuteSqlCommand("Truncate table LogErrors");
Blog | Twitter : @Hattan