本文介绍了FluentNHibernate:只是另一个映射问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
改变列名 CompositeId()。KeyReference(x => x.Key,/ * THIS PART * /)
方法应使用哪种约定?我已经在FluentNHibernate.Conventions中使用了所有可用的约定,并且还没有找到答案。
在此先感谢
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;
}
}
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
解决方案
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";
}
}
这篇关于FluentNHibernate:只是另一个映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-24 03:11