I've an one-to-one assocation and tried to get lazy load. I get a lot of
information of (N)Hibernate from search engine, but it confused me even more.
Some people say that I cannot get this but some others say yes. I tried with
these information but failed. Here's what I use as the model:
public class User
{
public virtual int UserID { get; set; }
public virtual string Name { get; set; }
public virtual UserDetail Detail { get; set; }
}
public class UserDetail
{
public virtual int UserID { get; set; }
public virtual int Age { get; set; }
public virtual User User { get; set; }
}
The mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHTest"
namespace="NHTest">
<class name="User" table="`User`">
<id name="UserID" type="Int32" column="UserID">
<generator class="identity" />
</id>
<one-to-one name="Detail" class="UserDetail" lazy="proxy" />
<property name="Name" type="String">
<column name="Name" />
</property>
</class>
<class name="UserDetail" table="`UserDetail`" lazy="true">
<id name="UserID" type="Int32" column="UserID">
<generator class="foreign">
<param name="property">User</param>
</generator>
</id>
<one-to-one constrained="true" name="User" class="User" />
<property name="Age" type="Int32">
<column name="Age" />
</property>
</class>
</hibernate-mapping>
When I tried to get an User instance by "session.Get<User>(10)", NH execute the
SQL:
SELECT
user0_.UserID as UserID0_1_,
user0_.Name as Name0_1_,
userdetail1_.UserID as UserID1_0_,
userdetail1_.Age as Age1_0_
FROM
[User] user0_
left outer join
[UserDetail] userdetail1_
on user0_.UserID=userdetail1_.UserID
WHERE
user0_.user...@p0;
@p0 = 4
What I need is just get the User instance but set a proxy of UserDetail for
lazy loading. I use Castle as byte code provider. Any thing wrong?
Blog: http://www.cnblogs.com/JeffreyZhao/
Twitter: http://twitter.com/jeffz_cn
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---