IJoinedSubclassInstance.Key.Column("keyname") does not change the mapped key column for sub class using Automapping

Ilias's Avatar

Ilias

26 Mar, 2010 10:44 AM via web

Hi,

I want to be able to use a custom key name for my sub-classes in a table per subclass approach.
If I have -

Class Base
{
    int BaseId {get; set;}
    string BaseProperty1 {get; set;}
}

Class Derived : Base
{
   string DerivedProperty1 {get; set;}
}

Table - 

Base
--------
BaseId - PK
BaseProperty1

Derived
--------
DerivedId - PK, FK
DerivedProperty1

I then apply a custom convention

 public class MyJoinedSubclassConvention : IJoinedSubclassConvention
  {
    #region IConvention<IJoinedSubclassInspector,IJoinedSubclassInstance> Members

    public void Apply(FluentNHibernate.Conventions.Instances.IJoinedSubclassInstance instance)
    {
      instance.Key.Column("DerivedId");
    }

    #endregion
}

The generated mapping still uses 'BaseId' when querying the derived classes
.

So the following query is generated

Select baseid, baseproperty1, derivedproperty1 
from Derived 
   inner join Base 
on base.baseid = derived.baseid

rather than

Select baseid, baseproperty1, derivedproperty1 
from Derived 
   inner join Base 
on base.baseid = derived.derivedid

    Reply to this discussion

    Preview Comments are parsed with Markdown. Help with syntax

    Attached Files

      You can attach files up to 10MB

      What is two plus two?