I have been struggling with this issue, couldn't find a solution yet.
I have the following situation (I've cut non-necessary parts):
public class Company : Base // Base has Guid Id
{
public virtual HeadQuarter HeadQuarter { get; set; }
}
public class HeadQuarter : Base
{
public virtual Company Company { get; set; }
}
Mappings:
public CompanyMap()
{
Id(x => x.Id).Column("CompanyId");
References(x => x.HeadQuarter)
.Column("HeadQuarterId")
.Unique()
.Cascade.All();
}
public HeadQuarterMap()
{
Id(x => x.Id)
.Column("HeadQuarterId");
HasOne(x => x.Company)
.PropertyRef(x => x.HeadQuarter)
.Cascade.All();
}
That generates two tables in my DB. I can insert a Company with a HeadQuarter. It works fine.
The problem is that when I remove a Company, the HeadQuarter doesn't get deleted. That's why I use cascading.
How can I achieve that?
I'd say, that the mapping should be inversed. Check the doc
HasOne / one-to-one
So, in our case, we would need the