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

查看:72
本文介绍了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

推荐答案

属性访问策略在参考文档中的 5.1.9.属性.

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

使用access属性可以控制NHibernate在运行时如何访问该属性的值.访问属性的值应为格式为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:

  • 属性.默认实现. NHibernate使用属性的获取/设置访问器.此命名策略不应使用任何命名策略,因为name属性的值是属性的名称.
  • 字段 NHibernate将直接访问该字段. NHibernate使用name属性的值作为字段的名称.如果您希望属性的名称而不是字段是您的API使用者与HQL一起使用的名称,则需要一种命名策略.
  • 发声器 NHibernate将在设置值时直接访问该字段,并在获取值时使用属性.因为NHibernate使用name属性的值作为属性名称,并且需要告知字段名称是什么,所以需要一种命名策略.
  • ClassName 如果您的情况不需要NHibernate的内置访问策略,则可以通过实现NHibernate.Property.IPropertyAccessor接口来构建自己的访问策略.访问属性的值应该是可以通过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 (姓名驼峰下划线)将name属性转换为驼峰式大写字母,并在名称前加上下划线以查找该字段.
  • 小写:name属性被转换为小写字母以查找字段.
  • 小写的下划线 name属性被转换为小写并以下划线作为前缀,以查找字段.
  • pascalcase-underscore (名称),名称属性带有下划线以查找字段.
  • 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天全站免登陆