使用判别器的 Fluent NHibernate 的多级继承

发布于 2024-12-16 11:19:11 字数 524 浏览 3 评论 0原文

我处于令人羡慕的境地,必须与遗留数据库集成,幸运的是出于只读目的,并且选择使用 NHibernate。到目前为止,一切都很好,但我有一个新的要求,让我摸不着头脑。

在今天之前,我在表中有一列可以充当鉴别器,但现在事实证明,在某些情况下我需要有多个鉴别器列。 NHibernate 可以做到这一点吗?

我研究过使用公式,它有效,但现在我遇到的问题是我需要排除“未知”子类(尚未具有映射的子类)。例如,我有这个:

DiscriminateSubClassesOnColumn("")
    .Formula("case ... when ... then ... when .. then ... else 'unknown' end");

我希望能够过滤掉所有“未知”的内容...

编辑:我认为一个可能的解决方案是使用 AlwaysSelectWithValue(),这意味着什么启用这个有吗?我相信它与 nhibernate 映射 xml 中的 force 相同。

I'm in the enviable situation of having to integrate with a legacy database, luckily for readonly purposes, and have chosen to use NHibernate. Up until now everything has been great, but I have a new requirement which has me scratching my head.

Before today I had one column in the table that would act as a discriminator, but now it turns out that in some cases I need to have more than one discriminator column. Is this possible with NHibernate?

I've looked into using formulas, which works, but now I have the issue that I need to exclude 'unknown' subclasses (ones that don't yet have a mapping). For example I have this:

DiscriminateSubClassesOnColumn("")
    .Formula("case ... when ... then ... when .. then ... else 'unknown' end");

I'd like to be able to filter out everything that is 'unknown'...

Edit: I think that a possible solution would be to use AlwaysSelectWithValue(), what implications does enabling this have? I believe it's the same as force in the nhibernate mapping xml.

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

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

发布评论

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

评论(1

无人接听 2024-12-23 11:19:11
public BaseClassMap()
{
    Where("discriminatorColumn <> 'unknown'");
    // or
    Where("discriminatorColumn = 'known1' or discriminatorColumn = 'known2'");
}
public BaseClassMap()
{
    Where("discriminatorColumn <> 'unknown'");
    // or
    Where("discriminatorColumn = 'known1' or discriminatorColumn = 'known2'");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文