Hi
I have been having some problems and would be grateful for any guidance on
an issue I am having.
For simplicity I have created the following test class and mappings to
demonstrate the issue I have:
public class House
{
public virtual int id { get; set; }
public virtual string name { get; set; }
}
<class name="Test.House" table="House">
<id name="id" type="System.Int32">
<generator class="assigned" />
</id>
<property name="name" insert="false" lazy="true" />
</class>
When performing the following test the assertion statement fails because
name is always null, i.e. NHibernate does not generate a proxy for this
field.
using (var session = NHibernateHelper.OpenSession())
using (var tx = session.BeginTransaction())
{
var house = new House()
{
id = 1,
name = "test",
};
session.Save(house);
tx.Commit();
}
using (var session = NHibernateHelper.OpenSession())
using (var tx = session.BeginTransaction())
{
var house = session.Get<House>(1);
Debug.Assert(house.name != null); // FAILS HERE
tx.Commit();
}
If I remove the insert="false" from the name property mapping like below,
the name property is assigned a proxy by NHibernate and the Assert passes.
<property name="name" lazy="true" />
It looks like the only way to get NHibernate to populate this field is to
use the following HQL query:
session.CreateQuery("from House h fetch all properties where h.id =
:id).SetParameter("id", 1);
Any ideas?
Does anybody know if this behaviour is by design?
Thanks in advance
Michael
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.