Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:45:33+00:00 2026-06-18T12:45:33+00:00

I have 2 objects in my domain A, and B Object A has a

  • 0

I have 2 objects in my domain A, and B

Object A has a property of B
Object B has a property of list

when I do a hit on my db, of B, it returns a list of As, but each A has a B, which in turn has a list of As. over and over and over.

clearly a lazy loading issue. Lazy loading is on, but my problem is that this is a WCF service, do i need to convert all my domain objects into dto objects to send down the wire and when i do it does the following – pseudocode

ADTO adto Transform(ADomain a)
{
   adto.name = a.name;
   adto.surname = a.surname;
   adto.B = Transform(a.B);
}

BDTO bdto Transform(BDomain b)
{
   bdto.bob = b.bob;
   foreach (A a in b.As)
   {
       bdto.bs.add(Transform(a));
   }
}

so how can i make my fetch of the collection only go one layer deep.

B’s mapping:

HasMany(x => x.As)
            .Cascade.AllDeleteOrphan()
            .Fetch.Select()
            .Inverse().KeyColumn("AId");

A’s mapping:

 References(x => x.B).Column("AId");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:45:34+00:00Added an answer on June 18, 2026 at 12:45 pm

    Well, to pass circular reference over WCF you should adjust the Parent DTO (B) with IsReference parameter DataContractAttribute.IsReference Property (or here The Problem of Circular References).

    Use the IsReference property to instruct the DataContractSerializer to insert XML constructs that preserve object reference information.
    [DataContract(Namespace = "http://domain.../", IsReference=true)] public class BDTO …

    To give you answer:

    …so how can i make my fetch of the collection only go one layer deep.

    NHibernate won’t have any issue with circular references. And even more, you can easily get all the data while executing 2 SQL queries only. Adjust the mapping:

    HasMany(x => x.As)
      .Cascade.AllDeleteOrphan()
      .BatchSize(25)
      //.Not.LazyLoad()
      .Inverse()
      .KeyColumn("AId");
    

    NOTE: Not.LazyLoad make sense only if the A object is almost always needed to get B working. When “lazy” mode is used, you have to keep the session opened during the whole WCF service processing

    The BatchSize setting will optimize loading lists of B objects. Read more here: http://ayende.com/blog/3943/nhibernate-mapping-set

    NHibernate session will execute two queries 1) Select B and 2) Select A for all B and materialize the results into complete A and B instances, with both-ways references fully populated. The NHibernate session will serve you fully loaded instances. Even calls Get<A>(id) and Get<B>(id) will retrieve the objects from session

    Next steps are up to you, you can use DTO objects, mapping tools to convert them…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a an object stored in the model called domain, which has two
I have this huge domain object(say parent) which contains other domain objects. It takes
I have a property on my domain object which is exposed as this: public
I have a List<> of custom objects. This custom type has a property called
I have a domain object that has been auto generated for me by MyGeneration.
Some of my PHP domain objects have properties which should be set from outside
I have a hibernate object called User which has a many-to-many relationship with another
I have a domain object called Campaign which contains a few string properties and
I have an object from my domain model that has a child object. How
I have a domain object, Expense, that has a field called initialFields . It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.