Question

I'm trying to delete all the records from a table using this approach:

new Delete<Contact>().Execute();

This statement fails with a NullReferenceException in BuildDeleteStatement method at line:

sb.Append(query.FromTables[0].QualifiedName);

Because, although FromTables has one entry, it is set to null. I also tried this but it doesn't worked either:

var provider = ProviderFactory.GetProvider("MonitorData");
new Delete<Contact>(provider).Execute();

What am I doing wrong?

Was it helpful?

Solution

You can do this with the repo DeleteMany method:

SubSonicRepository<Contact> repo = new SubSonicRepository<Contact>(new YourDB());
repo.DeleteMany(contact => true);

The lambda I'm using is just to ensure all records are selected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top