流畅的 Nhibernate AutoMapping 继承和忽略抽象属性
我有一个继承结构,我已成功映射
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Fluent NHibernate 有一个忽略属性方法,您可以在设置中使用该方法:
顺便说一句,我们通过向基类添加 Self 属性解决了这个问题。此属性将始终返回正确的(非代理)类型:
Fluent NHibernate has an ignore proprty method that you can use in the setup:
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: