views:

445

answers:

1

I am a little stuck at the moment 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 didn't worked either:

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

What am I doing wrong? Please help. Thanks.

PS: I am using ActiveRecord with SS v3.0.0.3.

+3  A: 

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 (thanks dangph).

Adam
Thanks. It did the trick.
Yogesh
repo.DeleteMany<Contact>(c => true);
dangph
You mean "repo.DeleteMany(c => true);" ?
Yogesh