Richie

Sometimes at night when I look up at the stars, and see the whole sky just laid out there, don't you think I ain't remembering it all. I still got dreams like anybody else, and ever so often, I am thinking about how things might of been. And then, all of a sudden, I'm forty, fifty, sixty years old, you know?

NHibernate access attribute

NHibernate documentation:

The built in ways of accessing the values of Properties in your domain class are:
Access Method How NHibernate accesses the Mapped Class
property
The name attribute is the name of the Property. This is the default implementation.
field
The name attribute is the name of the field. If you have any Properties in the Mapped Class those will be bypassed and NHibernate will go straight to the field. This is a good option if your setters have business rules attached to them or if you don't want to expose a field through a Getter & Setter.
nosetter
The name attribute is the name of the Property. NHibernate will use the Property's get method to retreive the value and will use the field to set the value. This is a good option for <id> Properties because this access method allow's users of the Class to get the value of the Id but not set the value.
Assembly Qualified Name
If NHibernate's built in IPropertyAccessors are not what is needed for your situation then you are free to build your own. Provide an Assembly Qualified Name so that NHibernate can call Activator.CreateInstance(AssemblyQualifiedName) to create it.

In order for the nosetter to know the name of the field to access NHibernate needs to know what the naming strategy is. The following naming strategies are built into NHibernate:
Naming Strategy How NHibernate converts the value of the name attribute to a field name
camelcase
The name attribute should be changed to CamelCase to find the field. <property name="Foo" ... > finds a field foo.
camelcase-underscore
The name attribute should be changed to CamelCase and prefixed with an underscore to find the field. <property name="Foo" ... > finds a field _foo.
pascalcase-underscore
The name attribute should be prefixed with an underscore to find the field. <property name="Foo" ... > finds a field _Foo.
pascalcase-m-underscore
The name attribute should be prefixed with an 'm' and underscore to find the field. <property name="Foo" ... > finds a field m_Foo.
pascalcase-m
The name attribute should be prefixed with an 'm'. <property name="Foo" ... > finds a field mFoo.
lowercase
The name attribute should be changed to lowercase to find the field. <property name="FooBar" ... > finds a field foobar.
lowercase-underscore
The name attribute should be changed to lowercase and prefixed with and underscore to find the field. <property name="FooBar" ... > finds a field _foobar.
The naming strategy can also be appended at the end of the field access method. Where this could be useful is a scenario where you do expose a get and set method in the Domain Class but NHibernate should only use the fields.
With a naming strategy and a get/set for the Property available the user of the Domain Class could write an Hql statement from Foo as foo where foo.SomeProperty = 'a'. If no naming strategy was specified the Hql statement whould have to be from Foo as foo where foo._someProperty (assuming CamelCase with an underscore field naming strategy is used).

So the build in values of the access attribute are:
property
field
field.camelcase
field.camelcase-underscore
field.lowercase
field.lowercase-underscore
field.pascalcase-underscore
field.pascalcase-m-underscore
field.pascalcase-m
nosetter.camelcase
nosetter.camelcase-underscore
nosetter.lowercase
nosetter.lowercase-underscore
nosetter.pascalcase-underscore
nosetter.pascalcase-m-underscore
nosetter.pascalcase-m

posted on 2007-08-04 05:36  riccc  阅读(2141)  评论(0编辑  收藏  举报

导航