Fluent NHibernate is bringing ClassMap Id and SubClassMap Id to referenced table?
- by Andy
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