Re: How to return only Parent Entity not including with child entity in Nhibernate?

25 views
Skip to first unread message

Jason Meckley

unread,
Dec 4, 2012, 12:19:36 PM12/4/12
to nhu...@googlegroups.com
don't fetch any of the related entities.

var entity = session.Get<Entity>(id);
var entity = session.QueryOver<Entity>().Where(...).Take(1).FutureValue();

you'll still be able to traverse the entity and lazy load the other relationships. like this

entity.Child.GrandChild.Value

If you don't want that you will need to detach the entity from the session.

var entity = session.Get<Entity>(id);
session.Detach(entity);

On Tuesday, December 4, 2012 5:01:22 AM UTC-5, Usman Khan Mohammad wrote:
I want to get only Parent entity object excluding its child entity's. How to do that.

Michael Möhle

unread,
Dec 6, 2012, 9:12:49 AM12/6/12
to nhu...@googlegroups.com

Set lazy=true and everything will be fine. That is the meaning of lazy!

 

Michael

 

From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Usman Khan Mohammad
Sent: Thursday, December 06, 2012 6:15 AM
To: nhu...@googlegroups.com
Subject: [nhusers] Re: How to return only Parent Entity not including with child entity in Nhibernate?

 

I used bag concept. Whenever I Get the parent, all child entities also getting. I have a particular scenario that should get only parent entity. 

 

In My hbm file  I written as follows:

 

Parent Hbm file:

 

<bag name ="ChildEmployeeDetails" lazy="false" inverse="true" cascade="all">

      <key column ="ParentEmployeeId" />

      <one-to-many class ="ParentEmployee" />

    </bag>

 

Child Hbm file:

 

<many-to-one name="ParentEmployee" class="ParentEmployee" column="ParentEmployeeId" lazy ="false"

                  cascade="all" />

 

Now, I Get the entity like,

 

var entity = session.Get<ParentEmployee>(id);

 

here I am getting both Parent and Child records. I want only Parent records not child. How to code?

 

 

 


On Tuesday, December 4, 2012 3:31:22 PM UTC+5:30, Usman Khan Mohammad wrote:

I want to get only Parent entity object excluding its child entity's. How to do that.

--
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/-/TNqRWZYFctoJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Reply all
Reply to author
Forward
0 new messages