views:

32

answers:

1

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

+2  A: 

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

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 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 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.
Lachlan Roche