标记“已删除”而不是使用 Castle ActiveRecord 进行物理删除
在我当前的项目中,我们收到了一个相当不寻常的请求(对我来说)。客户端希望所有的删除过程都标记一个标志,而不是从数据库表中物理删除记录。乍一看似乎很简单。我只是改变了
public void DeleteRecord(Record record)
{
record.DeleteAndFlush();
}
public IList GetAllRecords()
{
Record.FindAll().ToList();
}
,
public void DeleteRecord(Record record)
{
record.Deleted = true;
record.UpdateAndFlush();
}
public IList GetAllRecords()
{
Record.FindAll().Where(x=>x.Deleted==false).ToList();
}
但在我有一点时间并再次思考之后。我发现这个小小的改变会给我的级联设置带来很大的问题。因为我对 Active Record 业务还很陌生。我不相信自己能够简单地将所有 CascaeEnum.Delete 更改为 CascadeEnum.SaveUpdate。所以,我在这里寻找一些意见。
1)该标志是否是一种标志而不是常见的物理要求?
2) 如果问题 1 的答案是肯定的,那么我相信 NHibernate 中有内置的东西可以处理这个问题。有人可以告诉我解决此类问题的正确方法是什么吗?
感谢您的意见。
In my current project, we got a rather unusual request(to me). The client wants all the deletion procedure to mark a flag instead of physically delete the record from the database table. It looks pretty easy at the first glance. I just have change
public void DeleteRecord(Record record)
{
record.DeleteAndFlush();
}
public IList GetAllRecords()
{
Record.FindAll().ToList();
}
To
public void DeleteRecord(Record record)
{
record.Deleted = true;
record.UpdateAndFlush();
}
public IList GetAllRecords()
{
Record.FindAll().Where(x=>x.Deleted==false).ToList();
}
But as after I get a bit of time and think though again. I found that this little change would cause a huge problem in my cascade settings. As I am pretty new to the Active Record business. I wouldn't trust myself to simply change all the CascaeEnum.Delete to CascadeEnum.SaveUpdate. So, I am looking some input here.
1) Is the mark a flag instead of physical requirement a common one?
2) If the answer to question 1 is Yes, then I believe there is something built-in in NHibernate to handle this. Can someone tell me what is the right approach for this kind of problem?
Thanks for your input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这称为软删除,很常见。关于最佳实践存在一些争论 - 请查看最近的这篇博客文章:http://ayende.com/Blog/archive/2009/08/30/avoid-soft-deletes.aspx
This is known as Soft Deletes and it is very common. There is some debate about the best practice - check out this recent blog post: http://ayende.com/Blog/archive/2009/08/30/avoid-soft-deletes.aspx
这很常见,称为“软删除”。 这是 NHibernate 的实现。
This is quite common and called "soft delete". Here's an implementation of this for NHibernate.
这是一个相对常见的请求,有时出于(至少)两个原因实现它:
This is a relatively common request and it's sometimes implemented for (at least) two reasons: