nhibernate softdelete 覆盖位置
好的, 在我的解决方案中,我通过将 IsDeleted 设置为 true 而不是删除实体来实现软删除。
我还在类 Mapings 中添加了Where IsDeleted=false。
现在,我的所有选择查询都通过 where 执行,将结果限制为未删除的结果。
但现在在特定查询中我需要显示那些已删除的工具。 如何在某些查询中覆盖此行为?
请帮忙。 谢谢 卢卡
Ok,
In my solution I have implemented softdeletes by setting IsDeleted to true instead of deleting an entity.
I also added the Where IsDeleted=false in the class Mapings.
Now all my select queries get executed with the where that restricts the result to those that are not deleted.
But now in specific queries i need to show those that are deleted tool.
How can I override this behavior in some queries?
Please help.
Thanks
Luka
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
相反,我建议您使用过滤器来实现该功能。
您可以对具有 IsDeleted 列的所有实体启用此过滤器,然后在要搜索所有记录时显式禁用该过滤器。
它与此处描述的非常相似: NHibernate:创建适用于表上所有查询的条件
I would instead advice you to implement the functionality using filters instead.
You could enable this filter on all entities with IsDeleted column, and then explicitly disable the filter when you want to search for all records.
It is quite similar to what is described here: NHibernate: Creating a criteria which applies for all queries on a table
+1 过滤器非常适合类似的场景,但请记住它们不适用于多对一、一对一关联。
因此,对于类
Foo
和Bar
的情况,其中Bar
被软删除,Foo
指向Bar
并且关联已映射(即Foo.Bar
),如果您获取 Foo 并且 Bar 被软删除,则实体仍将被水合。当您包含这样的逻辑时,这是有问题的,
您可以通过对库进行简单的更改来更改此行为,我已经写了一篇文章
http://savale.blogspot.com/2010/01 /enabling-filters-on-mapped-entities.html 显示了如何执行此操作。它描述了 v2.1.2 的操作,但 v3.0+ pf NHibernate 的操作类似
+1 filter's work great for scenario's exactly like that but keep in mind they do not work on many-to-one, one-to-one associations.
So for the case of the classes
Foo
andBar
whereBar
is soft-deleted andFoo
points toBar
and the association is mapped (ie.Foo.Bar
) if you fetch Foo and Bar is soft deleted the entity will still be hydrated.This is problematic when you contain logic like
You can change this behavior by making a trivial change on the library, i have written a post on
http://savale.blogspot.com/2010/01/enabling-filters-on-mapped-entities.html that shows how to do that. It describes the opration for v2.1.2 but it's similar for v3.0+ pf NHibernate