views:

114

answers:

1

I'm trying to use the table-per-subclass (which fluent-nhibernate automaps by default) with a class structure like the following:

public class Product 
{
    public virtual int Id{ get; set; }
    public virtual string Title{ get; set; }
}

public class ProductPackage : Product
{
    public ProductPackage(){ Includes = new List<Product>(); }
    public virtual IList<Prodcut> Includes{ get; private set; }

    [EditorBrowsable( EditorBrowsableState.Never )]
    public class ProductPackageAutoOverride : IAutoMappingOverride<ProductPackage>
    {
     public void Override( AutoMap<ProductPackage> mapping )
     {
      mapping.HasManyToMany( x => x.Includes )
       .WithTableName( "IncludesXProduct" )
       .WithParentKeyColumn( "ProductId" )
       .WithChildKeyColumn( "IncludesProductId" )
       .Cascade.SaveUpdate();
     }
    }
}

Instead of adding a new table "IncludesXProduct" to represent the many-to-many mapping, it adds a property "ProductPackageId" to the Product table. Of course persisting to this schema doesn't work.

Have I missed something simple or is this type of thing not really supported by NHibernate?

A: 

It is possible to do this with NHibernate. Unfortunately my fluent syntax isn't very good, but it looks like FNH is somehow regarding the relationship as a many-to-one rather than a many-to-many.

If you tag your question with "fluent-nhibernate" then you may get more knowledgeable people answering.

John Rayner