How to truncate a table using LINQ (ntext)

Let’s say you have a relational database and you are using LINQ.

You want to delete all rows. You may use something like
Dim dc as new LinqDataContext
dc.DeleteAllOnSubmit (From z in dc.myTable)
dc.SubmitChanges()

This would work. However, it will generate a quite slow query and if you have a non-indexable column like an ntext one, the query will fail.

The easiest way to get rid of this is running a custom command:
dc.ExecuteCommand("TRUNCATE TABLE myTable")




One Comment

  1. SoulScanner wrote:

    Dude! You just totally saved us an extra 3 hours of our life! Thank you!!!!!