Foreign Key Lookup In Gridview

Foreign Key Lookup In Gridview

Old forum URL: forums.lhotka.net/forums/t/5107.aspx


Aver posted on Wednesday, July 16, 2008

Hello All,
   Just working away at using the framework and I really love it so far. However, I have a question.. its probably more design related but here goes :P

Here are my classes
User - Simply class to represent the application User
UserScorecards - List of UserScorecard Objects, User contains a reference to this object
UserScorecard - Used to represent a User Scorecard
Scorecard - Object used to represent a scorecard

Ok so each User has a list of scorecards (they can have more than 1)
The UserScorecard contains the ID (FK) of the Scorecard it represents.

What I am doing is binding the UserScorecards list to a GridView. However, I want to translate the ScorecardID to the Description of the scorecard instead of displaying the ID(foreign key). I do not anticipate changing the value so I do not want to use a DropDown box.

So right now the UserScorecard does not contain a reference to the scorecard is that the problem? Should I include a reference to the Scorecard object represented or is there an easy way (using maybe name/value pair) to translate the FK to the description? The reason I did not include the Scorecard object is because a Scorecard is not only used as a child of a UserScorecard (is that a switchable object then??)

JoeFallon1 replied on Wednesday, July 16, 2008

I am not sure why you have a 4th class. Normally all you need are the first three.

When you Fetch the UserScorecard it has the ID but not the Description, right?

Well then add the Description to the class as a "borrowed field" and populate it as part of your object when you fetch the data. Two ways to do that - 1. JOIN 2 DB tables in a query.  2. Use the one DB table to populate as normal, close the dr and then hit the DB once more using the ID to fetch the Description.

HTH

Joe

Aver replied on Wednesday, July 16, 2008

Ok I'm gonna laugh at myself.. The easiest and most obvious solution.

Thanks for the help

Copyright (c) Marimer LLC