how to create a foreign-key relationship without holding a reference to the father entity in fluent NHibernate

Viewed 137

I can't create a foreign-key relation ship with this setup. Please help! I have 3 classes:

Class Father
{
    Public Guid Id //This is the PK but I DON'T want to use this
    Public GuidWrapper myRealId //I need to use this unique id for the relation ship
}
Class Child
{
    Public Guid Id //not relevant. just to clarify this it the PK
    Public GuidWrapper dadId //I need to use this unique id for the relation ship
}
Class GuidWrapper
{
    Public Guid guid
}

also I have these relevant columns for the Father and Child tables:

Father table:
 column: myRealIdIdentifier uniqueidentifier
Child table:
 column: dadIdIdentifier uniqueidentifier

What I'm trying to do in fluent Nhibernate (using automappings, but I can do overrides) is create a foreign-key relation ship with cascade delete enabled where the child points at the father's myRealId which isn't the PK.

Notice the child DOES NOT have a reference to the father, I rather need to use the GuidWrapper as the foreign key property. Also notice that the underlying column names are not the same as the properties.

I tried various variations of this but to no avail because I'm new to Nhibernate:

childAutoMapping.References<Father>(x => x.dadId).Column("dadIdIdentifier")
                        .PropertyRef("myRealId");

Any help would be greatly appreicated!

0 Answers
Related