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

  • SEARCH
  • Home
  • 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 8400655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:36:49+00:00 2026-06-09T21:36:49+00:00

I have a table in C# and ASP.net that references a list of another

  • 0

I have a table in C# and ASP.net that references a list of another table where several vehicle registrants are mapped to a single vehicle. I do not want to go through the whole collection of vehicle registrants by accessing their individual members (e.g. vehicleRegistrantsAlias[0]), because I do not know how many there will be.

Do I need to do this in two queries? I really would like to do it all in one. I have the parent class as vehicle and a child collection of vehicle registrants. Vehicle registrant is a base type and under a vehicle registrant is the owner and operator. I also want to pull information form other child tables. I am joining from vehicle to vehicleRegistrants which works fine; however, I also want to pull owner and operant.

Vehicle vehicleAlias = null;
List<VehicleRegistration> vehicleRegistrationsAlias = null; 
List<VehicleRegistrant> vehicleRegistrantsAlias = null; 

.JoinAlias(() => vehicleAlias.VehicleRegistrations, () => vehicleRegistrationsAlias)
.JoinAlias(() => vehicleAlias.VehicleRegistrants, () => vehicleRegistrantsAlias)

//from vehicle registrants
.JoinAlias(() => vehicleRegistrantsAlias[0]., () => vehicleSuspensionTypeAlias)
  • 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-09T21:36:51+00:00Added an answer on June 9, 2026 at 9:36 pm

    You can use LINQ to NHibernate as well, it usually makes the queries easier to understand than the QueryOver API.

    Based on the comments, I guess you want a function with the following signature:

    public Vehicle GetVehicle(VehicleRegistrant registrant)
    {
        var vehicle = session.Query<Vehicle>()
                             .FetchMany(x => x.VehicleRegistrants)
                             .ThenFetch(x => x.Owner)
                             .Where(x => x.VehicleRegistrants.Contains(registrant))
                             .SingleOrDefault();
    }
    

    Or, if you have a relationship in the direction from VehicleRegistrant to its parent Vehicle, this would also work

    public Vehicle GetVehicle(VehicleRegistrant registrant)
    {
        var vehicle = session.Query<Vehicle>()
                             .FetchMany(x => x.VehicleRegistrants)
                             .ThenFetch(x => x.Owner)
                             .Where(x => x == registrant.Vehicle)
                             .SingleOrDefault();
    }
    

    I’m not sure if this is exactly what you wanted, but I believe you get the idea. FetchMany(x => x.VehicleRegistrants) tells NHibernate to also fetch all the VehicleRegistrants for each Vehicle in the result set and the following ThenFetch(x => x.Owner) tells “and for each of those VehicleRegistrants, also fetch its Owner“.

    Does this help?

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

Sidebar

Related Questions

I have an ASP.NET web app that places several string data into an object
We have several ASP.NET applications that use a sitemap which is populated via a
I have a ASP.NET/VB that had a GridView to display a list of users
I have a table of results in an ASP.Net MVC page where the last
My application is in ASP.net MVC3. I have a table of elements. An element
Context: ASP.NET MVC 2.0, C#, SQL Server 2008, IIS7 I have 'scheduledMeetings' table in
I have dragged a empty asp.net table onto my webform. I generate all the
I have an ASP.Net-MVC app using LinqToSql. I have a subcontracts table, a service_lines
I have an ASP.NET page and I am generating an HTML table in my
I have the following HTML generated by an ASP.NET repeater: <table> <tr> <td><input type=hidden

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.