从NHibernate 3切换到3.3.1后,找不到属性-异常 [英] Could not find the property - exception after switching from NHibernate 3 to 3.3.1

查看:89
本文介绍了从NHibernate 3切换到3.3.1后,找不到属性-异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有字段的班级:

I have a class with a field:

    protected DateTime insertDate;

这是针对这些领域的映射:

This is mapping for this fiels:

    <property name="InsertDate" access="field.camelcase" update="false" />

使用ctor时设置此字段

This field is set when with ctor

    public DocuBase(DateTime insertDate)

,并且仅在将行添加到数据库时才保留. 我完全不需要财产,不需要二传手&没有吸气剂.我在NHibernate 3中工作.

and is persisted only when row is added to the database. I don't need property for it at all, no setter & no getter. I worked in NHibernate 3.

现在,我已经从NHiberbate 3迁移到NHibernate 3.3.1,并且在创建会话工厂时遇到了此异常:

And now, I've moved from NHiberbate 3 to NHibernate 3.3.1, and I get this exception when session factory is created:

找不到与字段关联的属性"InsertDate" "insertDate",在"XXXX"类中

Could not find the property 'InsertDate', associated to the field 'insertDate', in class 'XXXX'

为什么会发生&如何更改映射以摆脱异常?

Why is is happening & how can I change mapping in order to get rid of the exception?

编辑:以下答案完全正确.但是对于那些不需要/不想拥有属性,而只有字段的人,还有另一种解决方案:

Below answer is completly correct. But for those of you that don't need/don't want to have a property, and only field, there's another solution:

  • 将名称属性设置为字段名称(在我的情况下为 insertDate ),并记住具有正确的列名称

  • set name attribute to field name (in my case it is insertDate) and remember to have correct column name

<property name="insertDate" column="InsertDate" access="field.camelcase" update="false" />

推荐答案

这是大小写敏感度,它将起作用.

It is case sensitivity, this will work.

<property name="insertDate" column="InsertDate" update="false" />

就像在3.1.0版本中一样,有一个重大更改

Looks like in release 3.1.0, there was a breaking change

NH现在接受以下代码.如果这样做会更好-在使用公共接口的属性名称(或memberinfo)通过hbm以外的其他方式配置NH(或第三方工具)时,这会导致问题.

[hbm]
<property name="Name" access="field.camelcase" />

[code]
string name;
public virtual string SomeThingCompletelyDifferent{
                                  get {return name;}
                                  set{name=value;}
}

注意:这将是一个重大变化.

ps-更新的答案,删除了对使用带有私有集的Property的引用,因为这不是要查找的内容,而在重大更改之上更有意义.

ps - updated answer to remove reference to use Property with private set as this was not what was being looked for and above breaking change is more relevant.

这篇关于从NHibernate 3切换到3.3.1后,找不到属性-异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆