I am trying to insert the price attributes for a price. The price inserts, but the price attributes to don't. Price attribute has a foreign key of pat_prc_key that references the price key. I have walked through a lot of the suggestions on Stack Overflow for setting up a child/parent relationship in Nhibernate, but I am stuck. Any suggestions would be greatly appreciated. I included all of the code below.
Price xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Api.Models.Price, Aafp.Also.Api" table="price" where="prc_delete_flag = 0">
<id name="Key" column="prc_key" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<property name="AddUser" type="String" column="prc_add_user" />
<property name="AddDate" type="DateTime" column="prc_add_date" />
<property name="ChangeUser" type="String" column="prc_change_user" insert="false" />
<property name="ChangeDate" type="DateTime" column="prc_change_date" insert="false" />
<property name="DeleteFlag" type="Boolean" column="prc_delete_flag" />
<property name="EntityKey" type="Guid" column="prc_entity_key" />
<property name="ProductKey" type="Guid" column="prc_prd_key" />
<property name="ProductTypeKey" type="Guid" column="prc_prd_ptp_key" />
<property name="ProductCompanyKey" type="Guid" column="prc_prd_atc_key" />
<property name="PriceCode" type="String" column="prc_code" />
<property name="PriceAmount" type="Decimal" column="prc_price" />
<property name="PricePercent" type="Decimal" column="prc_percent" />
<property name="PriceDisplayName" type="String" column="prc_display_name" />
<property name="PriceRevenueKey" type="Guid" column="prc_gla_revenue_key" />
<property name="PriceStartDate" type="DateTime" column="prc_start_date" />
<property name="PriceEndDate" type="DateTime" column="prc_end_date" />
<property name="PriceEwebCode" type="String" column="prc_eweb_code" />
<property name="RenewUnpaidOrdersFlag" type="Boolean" column="prc_renew_unpaid_orders_flag" />
<property name="AllowUnpaidOrdersFlag" type="Boolean" column="prc_allow_unpaid_orders_flag" />
<bag name="PriceAttributes" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="pat_prc_key" />
<one-to-many class="Api.Models.PriceAttribute, Api" />
</bag>
</class>
</hibernate-mapping>
Price Attribute xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Api.Models.PriceAttribute, Api" table="price_attribute" mutable="false" where="pat_delete_flag = 0">
<id name="Key" column="pat_key" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<property name="AddUser" type="String" column="pat_add_user" />
<property name="AddDate" type="DateTime" column="pat_add_date" />
<property name="ChangeUser" type="String" column="pat_change_user" />
<property name="ChangeDate" type="DateTime" column="pat_change_date" />
<property name="DeleteFlag" type="Boolean" column="pat_delete_flag" />
<property name="EntityKey" type="Guid" column="pat_entity_key" />
<property name="Code" type="String" column="pat_code" />
<many-to-one name="Price" class="Api.Models.Price, Api" column="prc_key" />
</class>
</hibernate-mapping>
Price Model
namespace Api.Models
{
public class Price
{
public virtual Guid Key { get; set; }
public virtual string AddUser { get; set; }
public virtual DateTime AddDate { get; set; }
public virtual string ChangeUser { get; set; }
public virtual DateTime ChangeDate { get; set; }
public virtual bool DeleteFlag { get; set; }
public virtual Guid EntityKey { get; set; }
public virtual Guid ProductKey { get; set; }
public virtual Guid ProductTypeKey { get; set; }
public virtual Guid ProductCompanyKey { get; set; }
public virtual string PriceCode { get; set; }
public virtual decimal PriceAmount { get; set; }
public virtual decimal PricePercent { get; set; }
public virtual string PriceDisplayName { get; set; }
public virtual Guid PriceRevenueKey { get; set; }
public virtual DateTime PriceStartDate { get; set; }
public virtual DateTime PriceEndDate { get; set; }
public virtual string PriceEwebCode { get; set; }
public virtual bool RenewUnpaidOrdersFlag { get; set; }
public virtual bool AllowUnpaidOrdersFlag { get; set; }
public virtual IList<PriceAttribute> PriceAttributes { get; set; }
}
}
Price Attribute Model
namespace Api.Models
{
public class PriceAttribute
{
public virtual Guid Key { get; set; }
public virtual string AddUser { get; set; }
public virtual DateTime AddDate { get; set; }
public virtual string ChangeUser { get; set; }
public virtual DateTime? ChangeDate { get; set; }
public virtual bool DeleteFlag { get; set; }
public virtual Guid EntityKey { get; set; }
public virtual string Code { get; set; }
public virtual Price Price { get; set; }
}
}
Task Code
var price = new Price
{
AddDate = DateTime.Now,
AddUser = webLogin,
PriceCode = activity.ActivityNumber,
PriceAmount = 0.00M,
PricePercent = 100.0000M,
PriceStartDate = DateTime.Now,
PriceEndDate = activity.ActivityEndDate.AddDays(1),
PriceEwebCode = activity.ActivityNumber,
RenewUnpaidOrdersFlag = true,
AllowUnpaidOrdersFlag = true,
PriceAttributes = new List<PriceAttribute>()
};
var priceAttribute = new PriceAttribute
{
AddDate = DateTime.Now,
AddUser = webLogin,
Code = activity.ActivityNumber
};
price.PriceAttributes.Add(priceAttribute);
priceAttribute.Price = price;
Command.Store(price);
public new void Store(Price price)
{
base.Store(price);
Session.Flush();
}