开发者

Fluent NHibernate: how to specify column name for reference in component using conventions?

开发者 https://www.devze.com 2023-02-22 14:05 出处:网络
It is possible to create ComponentConvention, but this code does not work because References collection is collection of IManyToOneInspector and not IManyToOneInstace.

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

精彩评论

暂无评论...
验证码 换一张
取 消