Mapping for vehicle (simple class)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property">
<class name="Binary.CMS.Models.Vehicle, App_Code" table="vehicles">
<id name="Id">
<generator class="identity" />
</id>
<property name="Name" length="45" not-null="true" column="name"/>
</class>
</hibernate-mapping>
Mapping for product:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property">
<class name="Binary.CMS.Models.Product, App_Code" table="products">
<id name="Id">
<generator class="identity" />
</id>
<property name="PartNumber" column="partno" />
<property name="ProductTitle" column="title" />
<property name="Description" column="description" />
<property name="Summary" column="summary" />
<property name="InStock" column="instock" />
<property name="AvailableToBuy" column="availabletobuy" />
<property name="Price" column="price" />
<property name="ImageFileName" column="imagefilename" />
<property name="Keywords" column="keywords" />
<property name="LastUpdated" column="timestamp" />
<property name="CategoryId" column="categoryid" />
<property name="Featured" column="featured" />
<bag name="Vehicles" table="productmodel">
<key column="product_id"/>
<many-to-many column="model_id"
class="Binary.CMS.Models.Vehicle, App_Code"/>
</bag>
</class>
</hibernate-mapping>
What I am trying to do is basically this:
Product x = new Product()
x.Vehicles.Add(vehicleA)
x.Vehicles.Add(vehicleB)
session.save(x)
The product row is written correctly, and rows in the productmodel table are written that manage the cross reference, but unfortunately the product_id on these rows is 0.
For existing product records it all works fine so I don't think the mapping is the problem?
Do I need to do this:
Product x = new Product()
session.save(x)
x.Vehicles.Add(vehicleA)
x.Vehicles.Add(vehicleB)
session.save(x)