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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:47:43+00:00 2026-05-11T19:47:43+00:00

My application has a very simple model right now and I’m trying to find

  • 0

My application has a very simple model right now and I’m trying to find the best way to traverse through an aggregate. As you can see in my model diagram at the bottom, I have an account, a trip and a list of people attending a trip. I would like to be able to view all of the trips an account is apart of and I have come up with something like this:

    public List<Trip> GetAllTripsFor(int accountid)
    {
        var tripRepository = new TripRepository();
        var trips = tripRepository.FindAll();
        var userTrips = new List<Trip>();

        foreach (Trip trip in trips)
        {
            foreach (TripPeople person in trip.People)
            {
                // If this trip's person list contains this accountid
                // then add this trip to the userTrips list.
                if(person.Account.Id == accountid)
                    userTrips.Add(trip);
            }
        }

        return userTrips;
    }

To me this doesn’t seem very efficient and that I’m not thinking about things correctly. Do any of you have ideas on a better way of implementing this? Perhaps I’m thinking about my model wrong? Thanks

alt text

  • 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-11T19:47:43+00:00Added an answer on May 11, 2026 at 7:47 pm

    thanks for your help. I think I figured out last night what I was trying to achieve. I’m not totally sure it’s the best way but it is working good so far. I was able to come up with an interface like the following:

    //Return a list of trips for the user
    var user = accountRepository.GetUserBy(123);
    var userTrips = user.Trips;
    
    //Return all of the users attending a trip
    var peopleAttendingTrip = tripRepository.GetTripBy(234).People;
    
    //Check user's status for a trip. A user must pay some kind of deposit
    //before they are considered active.
    var userStatus = userTrips.SingleOrDefault().GetStatusFor(user);
    

    To achieve this I created a many-to-many table that holds the the primary keys from User and Trip and then mapped the relationship in NHibernate to the User Class and Trip Class. Also to achieve the user’s status for a trip, I created an Entity that stores the user’s state along with the trip and user info. That’s a little duplication of data it seems like but I like the way it currently works and looks.

    If you guys have any comments or a better way to implement this let me know. I’m always up for improving something! Thanks again

    alt text

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

Sidebar

Related Questions

All I'm trying to do is open a very simple application that is supposed
I have a very simple MVVM Light application which has a textblock and a
This one has me utterly baffled... I have a very simple input model, with
I have a console application which has target .NET 2.0 It is very short
I have a 3yr old application that has some controllers with some very unrestful
I am building a web application using ASP.NET MVC that has two very distinct
Im Developing a web application which is very critical. So authentication has to be
I don't understand what's wrong in my very simple application with device rotation :
I'm trying to write a very simple cms (for learning purposes) in kohana 3
I have created a simple application which has a red background and a button

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.