|
Ok, so this has come up for debate and I wanted to see what you guys thought.
I have 3 logical objects; Players, Events, PlayerEvents (PlayerEvents is a table that contains PlayerEventID (PK), PlayerID (FK), EventID (FK), ....)
I think that by the naming it should be clear the mappings....but if it isn't just let me know.
Ok so here's the question. Say you want to know all the events the player has been to. Quite simple: SELECT * FROM PlayerEvents WHERE PlayerID = @PlayerID
The problem is that when I run the query above and want to display the results, you really don't have all the information that would be useful. The above query will tell you that at Event with the EventID 112, the player with PlayerID = 12, had a score of 10
PlayerEventID PlayerID EventID Score
20 12 112 10
In reality when you display this EventID 112 means nothing. REally you want to display the Events name, which requires you to go the the events table.
So finally after all of that here is the question...which of the following is the best way to accomplish that (best = speedy, easy to maintain, someone standard in the industry)
1) My business, PlayerEvent could simply have a member of type Event. Such that each PlayerEvent would load the individual event. I would access this in code by Player.Event.EventName.
The downfall to this I see is that for every PlayerEvent I load, I'm now loading an Event, which requires another call to the database. To help this I can offload the loading of the Event only when it's needed.
2) Have by business PlayerEvent have more members, including EventName, which would be readonly (via a property with only GET defined). I would avoid the pitfalls of #1 (above) by querying the database for the join (SELECT * FROM PlayerEvent INNER JOIN Event ON PlayerEvent.EventID = Event.EventID).
The downfall to this I see is that now my PlayerEvent object contains items that are not really related at all the the PlayerEvent object at all. Maybe I'm being overly anal by coding my business objects to look very similar to my database structure, if so please advise.
3) Something else I haven't thought of.
|