views:

29

answers:

1

I have a product object that contains 2 collections, accessories and consumers. Consumers relates to an accessory, the list of products that consume it. In the database I have a many to many relationship for these collections that is implemented as a linking table Product_Accessory. In mapping I have created a many to many one way for the accessories and the other way for consumers :

        mapping.HasManyToMany<oProduct>(x => x.Accessories)
            .Table("Product_Accessory")
            .Cascade.SaveUpdate()
            .ParentKeyColumn("ProductId")
            .ChildKeyColumn("AccessoryId")
            .AsBag();

        mapping.HasManyToMany<oProduct>(x => x.Consumers)
            .Table("Product_Accessory")
            .Cascade.SaveUpdate()
            .ParentKeyColumn("AccessoryId")
            .ChildKeyColumn("ProductId")
            .AsBag();

This all seems very logical but nHibernate is giving me an error of Found shared references to a collection because there are two lists of products.

Is this pattern possible using nHibernate? What is the best way to achieve this?

Thanks

Phil

A: 

I have solved the issue, I had a generic function that was setting all the product collections and creating a circular reference.

Phil Whittaker