-
Notifications
You must be signed in to change notification settings - Fork 684
Description
I'm fairly new to NHibernate and recently went over from ODM for this new project.
Not sure if I'm thinking crazy here with this design or this is a limitation in fnh:
My ShipmentPlan entity has two nullable columns, PackPlanId and LoadPlanId. They are referencing the same entity so I'm trying to figure out some kind of one-to-one mapping for both columns.
After desperate trial-and-errors, the only setup I have some success with is is the mapping below.
public ShipmentPlanMap()
{
References(x => x.PackPlan, "PackPlanId").Nullable().Cascade.SaveUpdate();
References(x => x.LoadPlan, "LoadPlanId").Nullable().Cascade.SaveUpdate();
}
public OptimizationPlanMap()
{
HasOne(x => x.ShipmentPlan).Cascade.All();
}
The problem is when I try to save the entity, even though the references looks right before saving, it crashed because ShipmentPlanId is not assigned and not in the insert query.
Entity before saving:
Query:
NHibernate xxxx: 2020-07-30 17:42:04.8 [9]: INSERT INTO [OptimizedPlan] (Created, CreatedBy, Updated, UpdatedBy, Name, ProjectId, PlanType, PlanConfigurationId) VALUES ('7/30/2020 9:42:04 AM', 'xxx', NULL, NULL, 'xxx', 1, 0, 3); select SCOPE_IDENTITY()
The success I had with this setup is I can fetch the entities correctly but as you see the saving part is not working.
Is this a issue in the design or mapping?