I tried upgrading today to nhibernate 3.2 from 3.1. The motivation for
this was the 'no-proxy' fix in 3.2 that prevents entities from being
eagerly loaded when the association is marked with 'no-proxy'. This is
fixed but now it seems the proxy is returned as opposed to the
underlying type. I am using fluent nhibernate with assembly
redirection on so it redirects to the newest version of nhibernate.
The xml mappings generated for the classes are also included. Example
public class Foo
{
public virtual int Id { get; set; }
public virtual int BarId { get; set; }
public virtual Bar Bar { get; set; }
}
public class Bar
{
public virtual int Id { get; set; }
public virtual int SomeInt { get; set; }
}
public class FooMap : ClassMap<Foo>
{
public FooMap()
{
Table("dbo.foo");
Id(i => i.Id);
Map(i => i.BarId);
References(i => i.Bar)
.LazyLoad(Laziness.Proxy)
.Column("BarId");
}
}
public class BarMap : ClassMap<Bar>
{
public BarMap()
{
Table("dbo.bar");
Id(s => s.Id);
Map(s => s.SomeInt);
}
}
Mapping xml
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2"
name="Test.Foo, Test, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"
table="dbo.foo">
<id name="Id"
type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="identity" />
</id>
<property name="BarId"
type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="BarId" />
</property>
<many-to-one class="Test.Bar, Test, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null"
lazy="no-proxy" name="Bar">
<column name="BarId" />
</many-to-one>
</class>
</hibernate-mapping>
Test:
[Test]
public void NoProxyLoadingWorks()
{
using (ISession session =
Util.SessionFactory.OpenSession())
{
Foo foo = session.Get<Foo>(4013);
int someInt = foo.Bar.SomeInt;
Assert.AreEqual("Bar", foo.Bar.GetType().Name);
}
}
Result:
Expected string length 3 but was 8. Strings differ at index 3.
Expected: "Bar"
But was: "BarProxy"
--------------^
This worked in 3.1 and is an example from the mappings file I use
(with changed names). Any assistance on this would be appreciated. I
have never used nhibernate without fluent nhibernate but will put
together a test now using the xml configuration to rule out fluent
nhibernate as being the cause of the issue. I would imagine if the
generated mappings were incorrect I would have experienced an error
building the session factory. The lack of errors during session
factory initialisation implies to me that there isn't an issue with
the mappings.
Thanks in advance.
--
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.