Taking an example that is provided on the Fluent nHibernate website, I need to extend it slightly:
alt text http://wiki.fluentnhibernate.org/images/2/24/FirstProjectSchema.png
I need to add a 'Quantity' column to the StoreProduct table. How would I map this using nHibernate?
An example mapping is provided for the given scenario above, but I'm not sure how I would get the Quantity column to map to a property on the Product class:
public class StoreMap : ClassMap<Store>
{
public StoreMap()
{
Id(x => x.Id);
Map(x => x.Name);
HasMany(x => x.Employee)
.Inverse()
.Cascade.All();
HasManyToMany(x => x.Products)
.Cascade.All()
.Table("StoreProduct");
}
}
One suggestion would be to not use the hasManyToMany mapping and have a separate mapping class for StoreProduct which is a subclass of Product.
New Store Mapping
NB changed HasManyToMany to HasMany instead.
New sub class mapping for Store Product
New StoreProduct entity
Hope that helps.