FluentNHibernate: Just another Mapping Question

2019-08-28 06:27发布

Which convention should be used to alter column name of CompositeId().KeyReference(x=>x.Key,/*THIS PART*/) method? I have used all available conventions in FluentNHibernate.Conventions and still haven't found the answer.

Thanks in advance

1条回答
\"骚年 ilove
2楼-- · 2019-08-28 07:10

still not possible now (FNH 1.2), except with some reflection-magic

class CompositeKeyConvention : ICompositeIdentityConvention
{
    public void Apply(ICompositeIdentityInstance instance)
    {
        var columninspector = instance.KeyManyToOnes.First(k => k.Name == "Key").Columns.First();

        var columnmapping = (ColumnMapping)columninspector.GetType().GetField("mapping", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic).GetValue(columninspector);

        columnmapping.Name = "mycolumnname";
    }
}
查看更多
登录 后发表回答