nhibernate 中的属性访问策略 [英] property Access strategies in nhibernate

查看:14
本文介绍了nhibernate 中的属性访问策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nhibernate xml的属性访问可以使用哪些访问策略?
有人可以向我指出其中可能使用的值吗?
一个不错的教程将不胜感激.
谢谢

What are the access strategies that I can use in the attribute access of the nhibernate xml?
Can someone point me the possible values to be used in it?
A nice tutorial would be very appreciated.
Thanks

推荐答案

Property Access 策略在 5.1.9.属性.

Property Access strategies are described in the reference documentation under 5.1.9. Property.

access 属性让你可以控制 NHibernate 在运行时如何访问属性的值.access 属性的值应该是文本格式,格式为 access-strategy.naming-strategy..naming-strategy 并非总是必需的.

The access attribute lets you control how NHibernate will access the value of the property at runtime. The value of the access attribute should be text formatted as access-strategy.naming-strategy. The .naming-strategy is not always required.

访问策略可以是以下之一:

Access strategy can be one of:

  • property 默认实现.NHibernate 使用属性的 get/set 访问器.此访问策略不应使用命名策略,因为 name 属性的值是属性的名称.
  • field NHibernate 将直接访问该字段.NHibernate 使用 name 属性的值作为字段的名称.如果您希望属性的名称而不是字段的名称成为 API 使用者与 HQL 一起使用的名称,则需要命名策略.
  • nosetter NHibernate 在设置值时会直接访问该字段,在获取值时会使用该属性.之所以需要命名策略,是因为 NHibernate 使用 name 属性的值作为属性名,需要告知字段的名称是什么.
  • ClassName 如果 NHibernate 的内置访问策略不是您的情况所需要的,那么您可以通过实现接口 NHibernate.Property.IPropertyAccessor 来构建自己的访问策略.access 属性的值应该是一个程序集限定的名称,可以使用 Activator.CreateInstance(string assemblyQualifiedName) 加载.
  • property The default implementation. NHibernate uses the get/set accessors of the property. No naming strategy should be used with this access strategy because the value of the name attribute is the name of the property.
  • field NHibernate will access the field directly. NHibernate uses the value of the name attribute as the name of the field. If you want the name of the property and not the field to be what the consumers of your API use with HQL, then a naming strategy is needed.
  • nosetter NHibernate will access the field directly when setting the value and will use the Property when getting the value. A naming strategy is required because NHibernate uses the value of the name attribute as the property name and needs to be told what the name of the field is.
  • ClassName If NHibernate's built in access strategies are not what is needed for your situation then you can build your own by implementing the interface NHibernate.Property.IPropertyAccessor. The value of the access attribute should be an assembly-qualified name that can be loaded with Activator.CreateInstance(string assemblyQualifiedName).

命名策略可以是以下之一:

Naming strategy can be one of:

  • camelcase name 属性转换为驼峰式大小写以查找字段.
  • camelcase-underscore 名称属性被转换为驼峰式大小写并以下划线为前缀以查找字段.
  • lowercase name 属性转换为小写以查找 Field.
  • lowercase-underscore name 属性被转换为小写并以下划线为前缀以查找字段.
  • pascalcase-underscore name 属性以下划线为前缀以查找字段.
  • pascalcase-m name 属性以字符 m 为前缀来查找字段
  • pascalcase-m-underscore name 属性以字符 m 和下划线为前缀以查找字段.
  • camelcase The name attribute is converted to camel case to find the field.
  • camelcase-underscore The name attribute is converted to camel case and prefixed with an underscore to find the field.
  • lowercase The name attribute is converted to lower case to find the Field.
  • lowercase-underscore The name attribute is converted to lower case and prefixed with an underscore to find the Field.
  • pascalcase-underscore The name attribute is prefixed with an underscore to find the field.
  • pascalcase-m The name attribute is prefixed with the character m to find the field
  • pascalcase-m-underscore The name attribute is prefixed with the character m and an underscore to find the field.

这篇关于nhibernate 中的属性访问策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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