Fluent NHibernate: how to specify column name for reference in component using conventions?
It is possible to create ComponentConvention, but this code does not work because References collection is collection of IManyToOneInspector and not IManyToOneInstace. Is there any other way to specify column?
public class ComponentConvention : IComponentConvention
{
public void Apply(IComponentInstance instance)
{
foreach (var inspector in instance.References)
{
inspector.Co开发者_高级运维lumn("some_name");
}
}
}
Sadly References aren't exposed in the same way as Properties and OneToOnes. You can access the underlying ComponentMapping with reflection and then create your own ManyToOneInstances with
var mapping = (ComponentMapping) typeof (ComponentInstance).GetField("mapping", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(instance);
foreach (var r in mapping.References)
{
var ri = new ManyToOneInstance(r);
ri.Column("some_name");
}
精彩评论