nhibernate softdelete 覆盖位置

发布于 2024-11-24 17:14:01 字数 218 浏览 1 评论 0原文

好的, 在我的解决方案中,我通过将 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 技术交流群。

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

发布评论

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

评论(2

仄言 2024-12-01 17:14:02

相反,我建议您使用过滤器来实现该功能。

您可以对具有 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

简单气质女生网名 2024-12-01 17:14:02

+1 过滤器非常适合类似的场景,但请记住它们不适用于多对一、一对一关联。

因此,对于类 FooBar 的情况,其中 Bar 被软删除,Foo 指向 Bar 并且关联已映射(即 Foo.Bar),如果您获取 Foo 并且 Bar 被软删除,则实体仍将被水合。

当您包含这样的逻辑时,这是有问题的,

if (Foo.Bar != null) {
   //will never execute
}

您可以通过对库进行简单的更改来更改此行为,我已经写了一篇文章
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 and Bar where Bar is soft-deleted and Foo points to Bar 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

if (Foo.Bar != null) {
   //will never execute
}

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

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