Im not supprised this doesn't feel right to you, it not. Infact it's so wrong it hurts! But instead of just just giving you grief ill explain all the reason why this is wrong.
Im not supprised this doesn't feel right to you, it not. Infact it's so wrong it hurts! But instead of just just giving you grief ill explain all the reason why this is wrong@ Firstly, your load in ALL the trips into memory from the database, this essentially means you are querying a data store to get a whole load of data that you don't need and then passing it down the wire.
This is fine if you have a few trips, but this will not scale at all. Next you are recursing through each trip and calling the property "trip. People".
This will then hit the database again and load ALL the data for people on EACH one of these trips. Again, this will kill you if you have several trips with several attendees. Now, this is assuming that you have no filters on your mappings or you have specifically asked Nbernate not to lazy load your People collection, but either way that's a whole load of data you don't want.My advice would be to look at the Nbernate documents concerning querying your object model using either HQL or Linq-To-N and you'll end up with queries that look something like the following: HQL (MY HQL Sucks so this could be very wrong): var hql = @"from Trip as t join t.
People as p with p.Account. Id = :accountId select t" Edit: Actually, my brain is a little slow right now as its late, but I just realized that your doing things a little backwards here. What your actually after is all the trips that an person has been on, so why doesn't your account object have a Trips collection mapped to is?
You should essentially be aiming for something like this: var trips = accountRepo. GetAccount(123). Trips; Edit: Again I am tired so this may be nonsense, but I think the mapping you are looking for will look like this: Edit: Damn it, I should go to bed.
Now I see you already have a mapping between the people and their trips so why not: var query = "from TripPeople as tp Where tp.Account. Id = :accountId AND tp. IsActive = true select tp.
Trip" Going to stop answering now, before I do more stupid things.
Thanks for the comment. Yeah this code stinks pretty bad but I'm a noob to Nbernate and programming good OO design. :P Yeah I totally agree that what I'm after is something like var trips = myAccount.
Trips but I'm really stuck on thinking this one through. Maybe the answer is in front of me but I'm a total idiot. I'm trying to figure out how I would map the Trip list in Account to data in the TripPeople aggregate.
I need to think about this for a while... – CalebHC Jun 8 '09 at 22:18 Assuming you have something like these tables: Trip, TripToAccount, Account then the mapping in the example will work for you (I think). – Owen Jun 8 '09 at 22:48 The only problem I'm running into is that my TripPeople table is an entity because it needs a state. – CalebHC Jun 9 '09 at 0:11 Yeah, I finally realized that in my last edit (doh!).
Would the HQL I posted not work, or are you trying to achieve this via a property mapping? If your trying to add it as a mapping, can you post what you have so far? – Owen Jun 9 '09 at 10:35.
What Owen said could be the best way to do it if you didn't load your trips before you hit this method. What I suggest would be to build some kind of compare() method for a class List of trips public class Trips: List { public Trips() { // // TODOÂ : // } #region methods /// /// return trip /// public Trip FindTrip(int accountId) { return this. Find(delegate(trip t) { return t.
AccountId == accountId; }); } #end region } I can't be sure if it's the best but that's the way I do it hahan hahan it's like the Find() method of the object class.
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 Nbernate 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.
1 Looks much more sensible :-) – Owen Jun 10 '09 at 14:48.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.