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: [email protected]
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 <[email protected]>
Tried but nothing changed.
Blog: http://www.cnblogs.com/JeffreyZhao/
Twitter: http://twitter.com/jeffz_cn
--------------------------------------------------
From: "hival" <[email protected]>
Sent: Saturday, August 15, 2009 11:09 PM
To: "nhusers" <[email protected]>
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 [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
-~----------~----~----~----~------~----~------~--~---