问题
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.
回答1:
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; }
}
来源:https://stackoverflow.com/questions/4802956/fluent-nhibernate-automapping-inheritance-and-ignoring-an-abstract-property