Fluent NHibernate is bringing ClassMap Id and SubClassMap Id to referenced table?

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-05-21T18:45:45Z Indexed on 2010/05/21 18:50 UTC
Read the original article Hit count: 735

HI,

I have the following entities I'm trying to map:

public class Product {
   public int ProductId { get; private set; }
   public string Name { get; set; }
}

public class SpecialProduct : Product {
   public ICollection<Option> Options { get; private set; }
}

public class Option {
   public int OptionId { get; private set; }
}

And the following mappings:

public class ProductMap : ClassMap<Product> {
  public ProductMap() {
    Id( x => x.ProductId );
    Map( x => x.Name );
}

public class SpecialProductMap : SubclassMap<SpecialProduct> {
  public SpecialProductMap() {
    Extends<ProductMap>();
    HasMany( p => p.Options ).AsSet().Cascade.SaveUpdate();
  }
}

public class OptionMap : ClassMap<Option> {
  public OptionMap() {
    Id( x => x.OptionId );
  }
}

The problem is that my tables end up like this:

Product
--------
ProductId
Name

SpecialProduct
--------------
ProductId

Option
------------
OptionId
ProductId          // This is wrong
SpecialProductId   // This is wrong

There should only be the one ProductId and single reference to the SpecialProduct table, but we get "both" Ids and two references to SpecialProduct.ProductId.

Any ideas?

Thanks Andy

© Stack Overflow or respective owner

Related posts about c#

Related posts about fluent-nhibernate