Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

property Access strategies in nhibernate

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

like image 876
marcelo-ferraz Avatar asked Feb 26 '10 03:02

marcelo-ferraz


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

What is fetch in NHibernate?

Fetching strategies. A fetching strategy is the strategy NHibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O/R mapping metadata, or overridden by a particular HQL or Criteria query.


1 Answers

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.
like image 168
Lachlan Roche Avatar answered Nov 26 '22 23:11

Lachlan Roche