【问题标题】:Loquacious Nhibernate not able to access non-public properties for mappingLoquacious Nhibernate 无法访问用于映射的非公共属性
【发布时间】:2012-04-30 02:23:40
【问题描述】:

我正在从流利转换为健谈,并且遇到了非公共财产的问题。当我尝试映射它时,nhibernate 会抛出一个异常,即 memberInfo 的值为空。我得到了最新的源代码并逐步查看发生了什么,它看起来像这样的调用:

memberOfReflectType = typeof (TEntity).GetProperty(memberOfDeclaringType.Name, memberOfDeclaringType.GetPropertyOrFieldType());

是导致问题的原因。 memberOfReflectType 被设置为 null,然后在 PropertyPath 构造函数中它在尝试访问它时中断。

我的映射如下所示:

public class Foo
{
  public virtual int SomePublicInt {get; set;}
  protected internal virtual int _someProtectedInt {get; set;}
}

public class FooMap : ClassMapping<Foo>
{
  public FooMap ()
  {
    Table("Foo");
    ComposedId(compIDMapper =>
    {
      compIDMapper.Property(x => x.SomePublicInt, m => m.Column("SomePublicInt"));
      compIDMapper.Property(x => _someProtectedInt, m => m.Column("SomeProtectedInt"));
    });
  }
}

如果我将受保护的内部 int 更改为公共 int,它可以正常工作,但您似乎应该能够映射受保护的内部。我们可以用 nhibernate 做到这一点,没有任何问题。

我必须输入一些额外的映射命令来解决这个问题吗?我用谷歌搜索了一段时间,但没有想到任何东西。

【问题讨论】:

    标签: c# nhibernate fluent-nhibernate


    【解决方案1】:

    对于非公共字段,尝试使用字符串而不是 lambda 表达式进行重载:

    compIDMapper.Property("_someProtectedInt", m => m.Column("SomeProtectedInt"));
    

    【讨论】:

    • 这解决了它,但你知道为什么需要它吗?
    • 不太确定,可能与 NHibernate 的代理能力有关。 Lambda 类型的重载仅适用于公共成员。
    猜你喜欢
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 2023-03-26
    • 2020-07-17
    • 2012-09-28
    • 1970-01-01
    相关资源
    最近更新 更多