I seem to have fixed it. I added CompositeID to the Deliverables mapping
CompositeId()
.KeyProperty(x => x.JobCode, "CODE")
.KeyProperty(x => x.Reference, "UNQREF");
This meant that I had to override the following in the Deliverable class
public override bool Equals(object obj)
{
if (obj == null)
return false;
var t = obj as Deliverable;
if (t == null)
return false;
if (JobCode == t.JobCode && Reference == t.Reference)
return true;
return false;
}
public override int GetHashCode()
{
return (JobCode + "|" + Reference).GetHashCode();
}
and then also changed the Job mapping as below
HasMany(x => x.Deliverables)
.KeyColumn("Codex")
.Inverse()
.Cascade.All();
I am not sure which of these has corrected the situation (I suspect the .Inverse()
in the Job mapping.
I am not sure what the generated SQL now looks like, but the answers look correct.