The session is being managed in another layer. So if I call down to _subService.GetChildStuff(childId) and retrieve the child, it calls, gets the info, eagerly loading some of the other child relationships and closes session. I don't want to add yet another join to the query when all I need is the parent id and nothing else at this point. Once I have the child I would like to be able to print the parent id to screen with Child.Parent.Id without having to go back to the db for the id itself.
The session is indeed closed at the point I call the parent id, but that is intended and expected behavior. I know I can go back and hydrate the parent object with another call, but I would prefer not to do that if possible. On Jun 28, 7:41 am, Ramon Smits <[email protected]> wrote: > I think you ment .Load<T> as I would expect your code to work but when using > Load<T> it would not. > > On Tue, Jun 28, 2011 at 2:11 PM, Jason Meckley <[email protected]>wrote: > > > > > > > > > > > you mentioned a session closed error. are you trying to access the value > > like > > > using(var session = factory.OpenSession()) > > { > > var entity = session.Get<Entity>(id); > > return entity.Parent.Id; > > } > > or > > using(var session = factory.OpenSession()) > > { > > var entity = session.Get<Entity>(id); > > } > > return entity.Parent.Id; > > > the first approach will work, then second would not. the scope of the > > session matters. > > > -- > > You received this message because you are subscribed to the Google Groups > > "nhusers" group. > > To view this discussion on the web visit > >https://groups.google.com/d/msg/nhusers/-/J4bYf3brY1UJ. > > > 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. > > -- > Ramon -- 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.
