Hi!
I've came across this problem , and no idea how to resolve the
situation.
I have a model such as:
entity1
hasmany(entity2)
entity2
hasmany(entity3)
at my test I am trying to get entity3 through entity1
and getting this message .
does anyone have some clue how to resolve it ?
my entities looks like this :
public class Entity1 : Entity
{
#region "Relationships"
private ICollection< Entity2> _col_ Entity2 = new HashSet<
Entity2 >();
public virtual ICollection< Entity2 > Col_ Entity2
{
get { return _col_ Entity2 ; }
protected set { _col_ Entity2 = value; }
}
#endregion
}
public class Entity2 : Entity
{
#region "Relationships"
private ICollection< Entity3> _col_ Entity3 = new HashSet<
Entity3 >();
public virtual ICollection< Entity3 > Col_ Entity3
{
get { return _col_ Entity3 ; }
protected set { _col_ Entity3 = value; }
}
#endregion
}
at the mapping :
public class Entity1 Mapping : ClassMap< Entity1 >
{
public Entity1Mapping()
{
try
{
LazyLoad();
Table("tableSource");
Id(x => x.ID).Length(10).Column("RECID");
Map(x => x.Col1).Column("COLUMN1");
HasMany<Entity2>(x => x.Col_ Entity2).AsBag()
.KeyColumn("COLUMN_OF_CHILD_TO_JOINBY")
.PropertyRef("Col1");
}
catch (NHibernate.HibernateException ex)
{
throw new Exception
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
}
}
}
----------------------
public class Entity2 Mapping : ClassMap < Entity2 >
{
//public virtual int Shm_medinaid { get; set; }
//public virtual int Shm_sherutid { get; set; }
public Entity2Mapping()
{
try
{
LazyLoad();
Table("tableSource2");
Id(x => x.ID).Length(10).Column("RECID");
Map(x => x.Col1).Column("COL1");
Map(x => x.Col2).Column("COL2");
HasMany<Entity3>(x => x.Col_Entity3).AsBag()
.KeyColumn("COLUMN_OF_CHILD_TO_JOINBY")
.PropertyRef("Col2");
}
catch (NHibernate.HibernateException ex)
{
throw new Exception
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
}
}
}
--------------------------------------
So at my test I am trying to reach the Entity3
[Test]
public void TestMapping()
{
Entity1 _entity1;
using (ISession Session =
NHibernateSessionProvider.GetSession())
{
long RECID = 847;
using (NHibernate.ITransaction Tran =
Session.BeginTransaction())
{
_entity1 = Session.Get< Entity1>(TMD_RECID);
Assert.AreNotEqual(_entity1.Col_Entity2, null);
IList<Entity2> _entity2 = new List<Entity2>
(_entity1.Col_Entity2);
IList<Entity3> _entity3 = new List<Entity3>
(_entity2[0].Col_Entity3);
Assert.AreNotEqual(_entity3[0].Col1, 0);
Tran.Commit();
}
}
}
-----------------------
I am failing at IList<Entity3> _entity3 = new List<Entity3>(_entity2
[0].Col_Entity3);
Initializing[Entity2#1]-failed to lazily initialize a collection of
role: Entity2.Col_Entity3, no session or session was closed
NHibernate.LazyInitializationException: Initializing[Entity2#1]-
failed to lazily initialize a collection of role:
Entity2.Col_Entity3, no session or session was closed
at
NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationException
(String message)
will appreciate any input on the subject .
--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en.