【问题标题】:How to delete all records in a table using SubSonic 3如何使用 SubSonic 3 删除表中的所有记录
【发布时间】:2009-08-26 08:26:25
【问题描述】:

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

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

该语句失败,NullReferenceException in BuildDeleteStatement method at line:

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

因为,虽然 FromTables 有一个条目,但它被设置为 null。我也试过了,但也没有用:

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

我做错了什么?

【问题讨论】:

    标签: activerecord subsonic subsonic3 delete-record


    【解决方案1】:

    您可以使用 repo DeleteMany 方法来做到这一点:

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

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

    【讨论】:

      猜你喜欢
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 2014-12-07
      相关资源
      最近更新 更多