流利Nhibernate AutoMapping继承和忽略抽象属性 [英] Fluent Nhibernate AutoMapping Inheritance and Ignoring an Abstract Property

查看:152
本文介绍了流利Nhibernate AutoMapping继承和忽略抽象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

产品(base)

PdfProduct(inherits从产品)&其他产品(从产品继承)



这些工作正常,我用hmb.xml文件做了一个类似的事情。


$ b $在前面的项目中,当我试图找出产品是什么类型时,我遇到了一个问题,但是由于它是一个代理(产品是PdfProdcut),所以我无法做到这一点。



为了解决这个问题,我向基础产品添加了一个抽象属性,并在返回一个枚举器的其他类中重写了它。



当我用xml映射做这个时,我根本没有映射类型列,一切都很好。



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



任何想法我怎么告诉它忽略这些?作为孩子的关系没有得到一个映射生成即时消息不知道在哪里把忽略语句。

任何帮助将得到很好的收到。


<流程NHibernate有一个可以忽略的方法,你可以在设置中使用:

 

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

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

  public virtual Product Self 
{
得到{return this; }
}


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.

解决方案

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; }
    }

这篇关于流利Nhibernate AutoMapping继承和忽略抽象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆