2

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.

sianabanana
  • 890
  • 1
  • 11
  • 28

1 Answers1

2

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; }
    }
Jamie Ide
  • 48,427
  • 16
  • 81
  • 117
  • I have added the self property and this works. and i overrode the product mapping to ignore self. This works because the property is in the product class – sianabanana Jan 28 '11 at 09:17
  • 1
    cant find ForTypesThatDeriveFrom. When i google it, it looks like this is old syntax? – sianabanana Jan 28 '11 at 09:21
  • If i do .Override(x => x.IgnoreProperty(y => y.Type)) This doesnt work. It still complains about the inherited types – sianabanana Jan 28 '11 at 09:22
  • 1
    And if i override them all... It still complains about MySql.Data.MySqlClient.MySqlException: Unknown column 'this_.Type' in 'field list' It just maps it anyways. but it doesnt exist in the database. – sianabanana Jan 28 '11 at 09:24
  • 1
    What class has method ForTypesThatDeriveFrom? – Sly Apr 20 '11 at 17:04
  • in 1.0 release this method was renamed – Sly Apr 20 '11 at 17:10