Hi All
In my project I have a Member class that looks something like this:
class Member
int Id (Primary Key, for DB only)
string UserCode (Unique, used by the outside world to retrieve the
Member)
...
For the purposes of my domain model I get the Members by their
UserCodes quite a few times within one NHibernate Session. Once at the
begining of the request to put their Roles into the secutity system
and then again for each service call.
I thought this would not be a problem as NHibernate would see that I
had already retrieved that member and not hit the DB to get it again.
However I have now realised that as I am not getting the Member by its
primary key (id) but by a secondary unique column (userCode) so
NHibernate does not use the Unit of Work / identity map and hits the
DB again. Although it does mainting reference equality, which is good.
Is there a way to tell NHibernate that even though I am not fetching
by the primary key the UserCode can also be considered an identifying
column? So if I've fetched a Member with userCode="X" another fetch
for Member.userCode="X" in the same session will not hit the DB again.
I have tried using the unique="true" attribute in the property element
in the mapping file but this does not seem to help with this issue.
Its also undocumented AFAICT so i'm not sure what it should do.
I suppose one solution is to keep my own UserCode to Id map in my
MemberRepository so the first call to GetByUserCode will get the
Member by UserCode and see what its Id is and then the subsequend
calls will re-route to GetById(). However I would feel much more warm
and fuzzy if I could get NHibernate to do this for me.
Comments, questions or sugestions most welcome.
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---