在 Fluent-nhibernate 中,您可以拦截选择查询以基于子类执行附加过滤

发布于 2024-10-20 23:25:45 字数 630 浏览 1 评论 0原文

我在这个网站上搜索了各种问题,他们几乎回答了我正在寻找的问题,但我无法将所有内容拼凑在一起以使其发挥作用。基本上我所拥有的是这样的:

class test: subclass
{
  int happyInt;
  //Other stuff goes here, doesn't really matter for this example.
}

class test2: subclass
{
  string happyString;
  //Other stuff goes here, doesn't really matter for this example.
}

class subclass
{
  int intIWantToFilterby;
}

我已经映射了所有内容,并且可以毫无问题地从数据库中获取数据,而且我什至有正在工作的拦截器,但基本上我想要的是每次执行选择进行测试时或 test2 作为选择的一部分我希望它检查 intIWantToFilterby 是否等于某个值。我意识到我可以手动执行此操作,但我有大量的类全部继承自子类,并且我不想编写完全相同的逻辑超过 100 次。到目前为止我还不知道如何做到这一点。也许我遗漏了一些明显的东西,但是从我在 Fluent 的网站和 nhibernate 的网站以及这里的搜索中,我还没有找到解决方案。

I've searched through various questions on this site, and they came close to answering what I'm looking for, but I haven't been able to piece everything together to get it to work. Basically what I had is something along these lines:

class test: subclass
{
  int happyInt;
  //Other stuff goes here, doesn't really matter for this example.
}

class test2: subclass
{
  string happyString;
  //Other stuff goes here, doesn't really matter for this example.
}

class subclass
{
  int intIWantToFilterby;
}

I have everything mapped and I can get data in and out of the DB without issue, and I even have interceptors that are working, but basically what I want is everytime a select is performed for test or test2 as part of the select I want it to check to see if intIWantToFilterby is equal to some value. I realize I can do this manually, but I have a large number of classes that all inherit from subclass and I don't want to have to write the exact same logic over a 100 times. So far I haven't been able to figure out how to do this. Maybe I'm missing something obvious, but from my searching on fluent's site and the nhibernate's site as well as here I haven't been able to find a solution yet.

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

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

发布评论

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

评论(1

木槿暧夏七纪年 2024-10-27 23:25:45

创建一个继承子类的新类,并将所有通用逻辑放入其中。现在创建 test 和 test2 并继承其他通用逻辑类。

Create a new class that inherits subclass and put all your generic logic/s in there. Now create test and test2 and inherit your other general logic class.

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