NHibernate设置access ="field.camelcase-underscore"在版本3中失败

big*_*7bb 5 nhibernate

我有一个用NHib 1.2创建的解决方案,我们正在升级到NHib 3.0.

我们的hbm文件具有以下属性:

<property name="ContentId" column="ContentId" access="field.camelcase-underscore" />
Run Code Online (Sandbox Code Playgroud)

该类没有ContentId属性.这在NHib 1.2中运行良好,但现在我们得到以下异常:

Could not compile the mapping document: XXXX.Core.Domain.Video.hbm.xml ---> NHibernate.MappingException: Problem trying to set property type by reflection ---> NHibernate.MappingException: class Core.Domain.Video, Core, Version=1.0.0.29283, Culture=neutral, PublicKeyToken=null not found while looking for property: ContentId ---> NHibernate.PropertyNotFoundException: Could not find the property 'ContentId', associated to the field '_contentId', in class 'Core.Domain.Video'.
Run Code Online (Sandbox Code Playgroud)

为什么这会停止工作?NHib 3还支持吗?

我们可能需要添加许多这样的属性.

Jam*_*acs 10

NHibernate极大地改进了NH2.X中的错误消息和诊断以及NH3.X中的错误消息和诊断.你告诉NHibernate你有一个属性,你想通过字段访问映射到_camelCase约定命名的字段.你没有名为ContentId的属性,NHibernate让你知道你撒谎了.:)

尝试将映射更新为:

<property name="_contentId" column="ContentId" access="field" />
Run Code Online (Sandbox Code Playgroud)

您需要更新任何HQL或Criteria查询以使用_contentId而不是ContentId.另一种选择是添加私有ContentId属性.