如何使用 SubSonic 3 删除表中的所有记录

发布于 2024-08-02 21:15:49 字数 464 浏览 2 评论 0原文

我正在尝试使用这种方法删除表中的所有记录:

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

此语句失败,并在 BuildDeleteStatement 方法中出现 NullReferenceException 行:

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

因为,虽然 FromTables 有一个条目,它被设置为空。我也尝试过这个,但它也不起作用:

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

我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾其所爱 2024-08-09 21:15:49

您可以使用 repo DeleteMany 方法来执行此操作:

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

我使用的 lambda 只是为了确保选择所有记录。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文