This is very similar to my previous question: FluentNHibernate: How to translate HasMany(x => x.Addresses).KeyColumn("PersonId") into automapping
Say
I've tested your classes with FHN's auto-mapping feature and it does not create that second PersonId on Address table. I'm using FHN v1.2.0.721 from here
Sigh... Learning NHibernate is really a hair pulling experience.
Anyway I think I finally figured out how to solve this problem: Just remove the SimpleForeignKeyConvention
and everything will work fine.
It seems the SimpleForeignKeyConvention
conflicts with both ReferenceKeyConvention
& KeyColumnConvention
. It has higher priority than KeyColumnConvention
but lower priority than ReferenceKeyConvention
.
public class SimpleForeignKeyConvention : ForeignKeyConvention
{
protected override string GetKeyName(Member property, Type type)
{
if(property == null)
// This line will disable `KeyColumnConvention`
return type.Name + "Id";
// This line has no effect when `ReferenceKeyConvention` is enabled.
return property.Name + "Id";
}
}