Correct use of Access Strategies (NHibernate)
Correct use of Access Strategies (NHibernate)
Hi,
I'm wondering if someone can provide me with a concrete example of how to use the Access Strategies in Entity Developer correctly.
For simplicity I've just created a very simple model that contains an abstract Entity with only an Int64 Id and inherited from that an Person with a String Name.
I've just selected all the defaults with the exception of the Default Access property of the model. However No matter what I set that property to, the generated classes always get out the same. Classes are partials (which they shouldn't be either I think) and its properties are available as Property.
What I'd ultimately like is the possibility to set a ClassName as described here: http://nhforge.org/doc/nh/en/index.html#d0e3588
However, getting access strategies working at all would be nice .
So, what am I doing wrong?
I'm wondering if someone can provide me with a concrete example of how to use the Access Strategies in Entity Developer correctly.
For simplicity I've just created a very simple model that contains an abstract Entity with only an Int64 Id and inherited from that an Person with a String Name.
I've just selected all the defaults with the exception of the Default Access property of the model. However No matter what I set that property to, the generated classes always get out the same. Classes are partials (which they shouldn't be either I think) and its properties are available as Property.
What I'd ultimately like is the possibility to set a ClassName as described here: http://nhforge.org/doc/nh/en/index.html#d0e3588
However, getting access strategies working at all would be nice .
So, what am I doing wrong?
Re: Correct use of Access Strategies (NHibernate)
The generated classes should remain the same. The strategy used for accessing the property value is stored in the XML mapping (ModelName.ClassName.hbm.xml). For example:PeterM wrote:However No matter what I set that property to, the generated classes always get out the same.
Code: Select all
<hibernate-mapping assembly="ConsoleApplication211" namespace="ConsoleApplication211" xmlns="urn:nhibernate-mapping-2.2">
<subclass name="Person" extends="Entity">
<property name="Name" type="String" access="field.pascalcase-underscore">
Re: Correct use of Access Strategies (NHibernate)
Ok, I get the idea there.
However I do see some errors when using it in combination with Fluent and Repository and UoW.
During the creation of the sessionFactory. So I'm guessing that somewhere during generation an unforeseen dependency isn't handled correctly. Bluntly changing the Properties to Fields won't solve the problems since it will start complaining when creating relations (wrt proxies).
Am I also correct in noticing a different implementation related to these access strategies in the XML mapping and Fluent? When using Fluent it simply sets it to Field() which assumes that it can access a field named exactly as the name of the property. While the XML mapping mentions the naming strategy pascalcase-underscore.
For now I'll just continue without Fluent (which might be a bit less error-prone) but I do think it should either work out of the box or produce some pointers that certain combinations are unlikely to work without manual intervention.
However I do see some errors when using it in combination with Fluent and Repository and UoW.
Code: Select all
Could not find property nor field 'Id' in class 'PM4.Model.Entity'
Am I also correct in noticing a different implementation related to these access strategies in the XML mapping and Fluent? When using Fluent it simply sets it to Field() which assumes that it can access a field named exactly as the name of the property. While the XML mapping mentions the naming strategy pascalcase-underscore.
For now I'll just continue without Fluent (which might be a bit less error-prone) but I do think it should either work out of the box or produce some pointers that certain combinations are unlikely to work without manual intervention.
Re: Correct use of Access Strategies (NHibernate)
A last (unrelated actually) remark wrt to my problems. Since I inherit everything from 'Entity' the primary key (Id) is defined only there. When creating relations it seems to have problems detecting that Id is not a good column to use for storing id's of related objects...
Re: Correct use of Access Strategies (NHibernate)
We have reproduced the problem and will post here when it is fixed.PeterM wrote:When using Fluent it simply sets it to Field() which assumes that it can access a field named exactly as the name of the property. While the XML mapping mentions the naming strategy pascalcase-underscore.
PeterM wrote:Could not find property nor field 'Id' in class 'PM4.Model.Entity'
Are these problems the result of the pascalcase-underscore issue? If not, send us a test model and specify the steps we should follow for reproducing.PeterM wrote:When creating relations it seems to have problems detecting that Id is not a good column to use for storing id's of related objects
Re: Correct use of Access Strategies (NHibernate)
Sorry for the late reply, but the last mentioned problem about the Id is not directly related to the naming issue (I assume anyway). The first bit, 'Could not find...' is however!
For that last part, I'll send a model that produces that behavior.
For that last part, I'll send a model that produces that behavior.
Re: Correct use of Access Strategies (NHibernate)
The bug with setting access strategy for the class property in fluent mapping is fixed. We will post here when the corresponding build of Entity Developer is available for donwload.
Re: Correct use of Access Strategies (NHibernate)
New build of Entity Developer 5.5.164 is available for download now!
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=27694.
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=27694.