Currently I'm using Fluent NHibernate to generate my database schema, but I want the entities in a HasMany relationship to point to a different column for the reference. IE, this is what NHibernate will generate in the creation DDL:
alter table `Pony` add index (Stable_ID),
add constraint Ponies_Stable foreign key (Stable_Id)
references `Stable` (Id);
This is what I want to have:
alter table `Pony` add index (Stable_ID),
add constraint Ponies_Stable foreign key (Stable_Id)
references `Stable` (EntityId);
Where Stable.ID would be the primary key and Stable.EntityId is just another column that I set.
I have a class already that looks like this:
public class ForeignKeyReferenceConvention : IHasManyConvention
{
public void Apply(IOneToManyCollectionInstance instance)
{
instance.Cascade.All();
//What goes here so that I can change the reference column?
}
}
What do I have to do to get the reference column to change?
As an example, here is what the code for IReferenceConvention looks like to do the same thing:
public class MyReferenceConvention : IReferenceConvention
{
public void Apply(IManyToOneInstance instance)
{
instance.PropertyRef("EntityId");
instance.Cascade.All();
}
}
EDIT:
instance.Key.Column("EntityId")
is not the solution.