How to delete all records in a table using SubSonic 3

点点圈 提交于 2019-12-11 08:41:01

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1333171/how-to-delete-all-records-in-a-table-using-subsonic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!