How to change Fluent NHibernate reference column name on a HasMany relationship using IHasManyConven

Posted by snicker on Stack Overflow See other posts from Stack Overflow or by snicker
Published on 2010-02-26T20:08:04Z Indexed on 2010/03/08 23:21 UTC
Read the original article Hit count: 1702

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?

© Stack Overflow or respective owner

Related posts about fluent-nhibernate

Related posts about nhibernate