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 6040435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:30:49+00:00 2026-05-23T06:30:49+00:00

I would like to return a DTO from my data layer which would also

  • 0

I would like to return a DTO from my data layer which would also contain child collections…such as this:

Audio
 - Title
 - Description
 - Filename
 - Tags
     -  TagName
 - Comments
     -  PersonName
     -  CommentText

Here is a basic query so far, but i’m not sure how to transform the child collections from my entity to the DTO.

var query = Session.CreateCriteria<Audio>("audio")
            .SetProjection(
                Projections.ProjectionList()
                    .Add(Projections.Property<Audio>(x => x.Title))
                    .Add(Projections.Property<Audio>(x => x.Description))
                    .Add(Projections.Property<Audio>(x => x.Filename))
            ).SetResultTransformer(new AliasToBeanResultTransformer(typeof(AudioDto)))
            .List<AudioDto>();

Is this even possible, or is there another reccomended way of doing this?

UPDATE:
Just want to add a little more information about my scenario…I want to return a list of Audio items to the currently logged in user along with some associated entities such as tags, comments etc…these are fairly straight forward using MultiQuery / Future.

However, when displaying the audio items to the user, i also want to display 3 other options to the user:

  • Weather they have added this audio item to their list of favourites
  • Weather they have given this audio the ‘thumbs up’
  • Weather the logged in user is ‘Following’ the owner of this audio
Favourites : Audio -> HasMany -> AudioUserFavourites

Thumbs Up : Audio -> HasManyToMany -> UserAccount

Following Owner : Audio -> References -> UserAccount ->

ManyToMany -> UserAccount

Hope this makes sense…if not i’ll try and explain again…how can I eager load these extra details for each Audio entity returned…I need all this information in pages of 20 also.

I looked at Batch fetching, but this appears to fetch ALL thumbs ups for each Audio entity, rather than checking if only the logged in user has thumbed it.

Sorry for rambling 🙂

Paul

  • 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-05-23T06:30:50+00:00Added an answer on May 23, 2026 at 6:30 am

    If you want to fetch your Audio objects with both the Tags collection and Comments collections populated, have a look at Aydende Rahien’s blog: http://ayende.com/blog/4367/eagerly-loading-entity-associations-efficiently-with-nhibernate.

    You don’t need to use DTOs for this; you can get back a list of Audio with its collections even if the collections are lazily loaded by default. You would create two future queries; the first will fetch Audio joined to Tags, and the second will fetch Audio joined to Comments. It works because by the time the second query result is being processed, the session cache already has the Audio objects in it; NHibernate grabs the Audio from the cache instead of rehydrating it, and then fills in the second collection.

    You don’t need to use future queries for this; it still works if you just execute the two queries sequentially, but using futures will result in just one round trip to the database, making it faster.

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

Sidebar

Related Questions

I have a function from which I would like to return a value as
So basically I would like my app to read info from a database, this
I would like to return a noncopyable object of type Foo from a function.
I am currently returning JSON data like this: return new JsonResult { Data =
I would like to return a string with all of the contents of a
I would like to use the API to return all tweets that match my
In an asp.net application, i would like to use a webservice to return the
I'd like ask a question about building applications in .NET that use data from
Using re in Python, I would like to return all of the characters in
I have a developed a Restlet application. I would like to return a JSP

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.