流畅的 Nhibernate AutoMapping 继承和忽略抽象属性

发布于 2024-10-14 18:36:41 字数 441 浏览 2 评论 0原文

我有一个继承结构,我已成功映射

Product (base)

PdfProduct (继承自 Product) &其他产品(继承自产品)

这些工作正常,我之前用 hmb.xml 文件做过类似的事情。

在上一个项目中,当我试图找出产品是什么类型时,我遇到了问题,但我无法做到这一点,因为它是代理(产品是 PdfProdcut)。

为了解决这个问题,我向基本 Product 添加了一个抽象属性,并在返回枚举器的其他类中覆盖了它。

当我使用 xml 映射执行此操作时,我只是没有映射“类型”列,一切都很好。

现在我尝试自动映射继承关系,它自动将抽象属性映射到子类,但这不是必需的,因为它不在数据库中。

我有什么想法告诉它忽略这些吗?由于子关系没有生成映射,因此我不确定将忽略语句放在哪里。

任何帮助都会受到极大的欢迎。

I have an inheritance structure that i have succesfully mapped

Product (base)

PdfProduct (inherits from Product) & OtherProduct(inherits from Product)

These are working fine and i have done a simmilar thing before with hmb.xml files.

In the previous project i had a problem when i was trying to find out what type the product was but i couldnt do it as it was a Proxy (product is PdfProdcut).

To solve this, i added an abstract property to the base Product and overrided it in the other classes returning an enumerator.

When i did this with the xml mappings i simply didnt map the Type column and all was well.

Now i am trying to auto map the inherited relationship, it automatically maps the abstract property to the child classes, but this is not needed as it isnt in the database.

Any ideas how i tell it to ignore these? as the child relationships dont get a mapping generated im not sure where to put the ignore statement.

Any help would be greatfully received.

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

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

发布评论

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

评论(1

一指流沙 2024-10-21 18:36:41

Fluent NHibernate 有一个忽略属性方法,您可以在设置中使用该方法:

.ForTypesThatDeriveFrom<Product>(p => p.IgnoreProperty(x => x.Type))

顺便说一句,我们通过向基类添加 Self 属性解决了这个问题。此属性将始终返回正确的(非代理)类型:

    public virtual Product Self
    {
        get { return this; }
    }

Fluent NHibernate has an ignore proprty method that you can use in the setup:

.ForTypesThatDeriveFrom<Product>(p => p.IgnoreProperty(x => x.Type))

By the way, we solved this problem by adding a Self property to the base class. This property will always return the correct (non-proxy) type:

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