How to change Fluent NHibernate reference column name on a HasMany relationship using IHasManyConven
- by snicker
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?