views:

181

answers:

0

I am a newbie to NHibernate and trying to create a XML mapping for this scenario:

public class Catalog
{
    public virtual Guid ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IDictionary<string, Product> Products { get; set; }
}

The key in the IDictionary is the name of the Product.

public class Product
{
    public virtual Guid ID { get; set; }
    public virtual string Name { get; set; }
}

The database tables are defined like that:

Catalog
    ID: uniqueidentifier
    Name: nvarchar(255)

CatalogProduct
    CatalogID: uniqueidentifier
    ProductID: uniqueidentifier

Product
    ID: uniqueidentifier
    Name: nvarchar(255)

In the Catalog class mapping, if I try to do something like that:

<map name="Products" table="CatalogProduct">
    <key column="CatalogID" />
    <index column ="?" />
    <many-to-many class="Product" column="ProductID" />
</map>

It obviously doesn't work because the column I want as the index is in another table.

Is there a proper mapping for that?

Thanks

Andrey

related questions