I'm using Fluent Nhibernate and my relevant entities are:
public class Product
{
public virtual int ID {get; set;}
public virtual string Name {get; set;}
public virtual Supplier Supplier {get; set;}
}
public class Supplier
{
public virtual int ID {get; set;}
public virtual string Name {get; set;}
public virtual List<Product> Products {get; set;}
}
In the mapping the supplier has HasMany on the Products + Inverse + Cascade.All in order to save all the prodcuts at once. My Product Primary Key and thus the equality members is the Id which is generated with NH sequence.
I need to create a list of products to a new supplier. Well if I add the products to the list before they get the primary key from the DB, only the first product being added to the list because the ID is 0 for all the products so the equals method return true, and the list "thinks" it already has that product.
I can save the products one by one before adding to the supplier list so the will get the Id value for the data base. But that doesn't use the cascade ability.
Any creative suggestion will be welcome.