FluentNHibernate: Just another Mapping Question

送分小仙女□ 提交于 2019-12-12 02:15:21

问题


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:


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";
    }
}


来源:https://stackoverflow.com/questions/7408672/fluentnhibernate-just-another-mapping-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!