I have a schema with an N:1
parent-child relationship that is stored in another table and is selected by a formula. Is it possible to map this entity to the parent using a formula?
public class ParentEntity {
public virtual int ParentId { get; set; }
public virtual ChildEntity Child{ get; set; }
}
public class ParentMapping : ClassMap<ParentEntity> {
public ParentMapping() {
Table("ParentTable");
Id(x => x.ParentId).Column("ParentId").GeneratedBy.Assigned().Not.Nullable();
References<ChildEntity>(x => x.Child).Formula(
@"(
SELECT TOP 1 ChildTable.ChildId
FROM ChildTable
WHERE ChildTable.ParentId = ParentId
)"
);
}
}
The SQL that this mapping generates looks like this:
SELECT
this_.ParentId,
this_.ChildEntity_id
FROM ParentTable this_
This is not what I'm looking for.
How can I reference this child entity and use, instead of ChildId
in the parent table, a formula that selects ChildId
from a formula?