I need to remove all records in a given table, using a DbContext in Entity Framework. I need this to be portable, so it can't rely on SQL statements or stored procedures. I've looked through the answers to this question, but none of them meet my requirements or are ideal solutions for a variety of reasons.
I could use the RemoveRange method, i.e.
DbContext.Table.RemoveRange(all);
But this doesn't scale well, because it selects all entries before deleting, which could take a long, long time with Entity Framework. Iterating through each record and removing them individually with Remove(record) has the same problem.
Using SQL this is simple, using a TRUNCATE command. Even a simple DELETE FROM [TableName] command works, but I don't know how scalable that is.
Is there any solution that uses only Entity Framework (no SQL), and doesn't require selecting all records first before deleting them?