What I'm using now is an ugly workaround. I changed my model like the code below and set an one-to-many mapping between User and UserDetail.
Everything's fine (save, update, delete, query with lazy or eager loading) except the bad taste in model - I really don't like it. public class User { public virtual int UserID { get; set; } public virtual string Name { get; set; } private ISet<UserDetail> m_detailLazyProxySet; private ISet<UserDetail> DetailLazyProxySet { get { if (this.m_detailLazyProxySet == null) { this.m_detailLazyProxySet = new HashedSet<UserDetail>(); } return this.m_detailLazyProxySet; } set { this.m_detailLazyProxySet = value; } } public virtual UserDetail Detail { get { return this.DetailLazyProxySet.Count <= 0 ? null : this.DetailLazyProxySet.Single(); } set { this.DetailLazyProxySet.Clear(); this.DetailLazyProxySet.Add(value); } } } Blog: http://www.cnblogs.com/JeffreyZhao/ Twitter: http://twitter.com/jeffz_cn From: Fabio Maulo Sent: Saturday, August 15, 2009 11:39 PM To: nhusers@googlegroups.com Subject: [nhusers] Re: Lazy load of one-to-one association let your app choose which is the real relationship and configure it as many-to-one for persistence scope (that is one of the reasons to use a persistent-layer based on ORM ;) ). 2009/8/15 Jeffrey Zhao <je...@live.com> Tried but nothing changed. Blog: http://www.cnblogs.com/JeffreyZhao/ Twitter: http://twitter.com/jeffz_cn -------------------------------------------------- From: "hival" <hi...@ukr.net> Sent: Saturday, August 15, 2009 11:09 PM To: "nhusers" <nhusers@googlegroups.com> Subject: [nhusers] Re: Lazy load of one-to-one association > > Try to specify constrained="true" in the User's side of the <one-to- > one> association.I'm not sure whether it is correct but it works. It > seems that NH doesn't look at the other side of the one-to-one assoc. > to find out whether the assoc. is optional or not. > > > > > -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to nhusers@googlegroups.com To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---