I am currently using Fluent NHibernate to create my database schema, but I want the entities from the HasMany relation to point to another column for the link. IE, this is what NHibernate will generate in creating 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 will be the main key, and Stable.EntityId is another column that I set.
I already have a class that looks like this:
public class ForeignKeyReferenceConvention : IHasManyConvention { public void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.All();
What do I need to do to change the reference column?
As an example, here is what the code for IReferenceConvention looks like to do the same:
public class MyReferenceConvention : IReferenceConvention { public void Apply(IManyToOneInstance instance) { instance.PropertyRef("EntityId"); instance.Cascade.All(); } }
EDIT: instance.Key.Column("EntityId") not a solution.
source share