【问题标题】:Fluent NHibernate: how to specify column name for reference in component using conventions?Fluent NHibernate:如何使用约定在组件中指定列名以供参考?
【发布时间】:2011-04-04 18:41:42
【问题描述】:

可以创建 ComponentConvention,但此代码不起作用,因为 References 集合是 IManyToOneInspector 而不是 IManyToOneInstace 的集合。 有没有其他方法可以指定列?

public class ComponentConvention : IComponentConvention
{
    public void Apply(IComponentInstance instance)
    {
        foreach (var inspector in instance.References)
        {
            inspector.Column("some_name");
        }
    }
}

【问题讨论】:

    标签: .net nhibernate orm fluent-nhibernate


    【解决方案1】:

    遗憾的是,引用的公开方式与属性和 OneToOne 不同。 您可以使用反射访问底层 ComponentMapping,然后使用

    创建您自己的 ManyToOneInstances
    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");
    }
    

    【讨论】:

    • 感谢您的解决方法,但它在 FNH 的下一个版本中引入了破坏更改的可能性很大,因此我将保留覆盖而不是使用此约定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多