I find myself writing a lot of functions like this...to get some sort of Name or Text or FullName field, based on the ID ...
public static string GetAnswerText(int answerID)
TreatmentIntegrityDataContext data = new TreatmentIntegrityDataContext();
Answer answer = data.Answers.FirstOrDefault(x => x.AnswerID == answerID);
if (answer == null)
I have one of these functions for almost every object in my database. Is there a way to consolidate this into one generic function? For example could I override the ToString() method for every object and then make a generic function GetStringValue(Type T, int primaryKey) that looks up the record based on the ID, and calls the ToString() method for an object of type T? What would that function look like?
I think it must be possible because I've playing around with a Dynamic Data website which does similar things ... I'm just not sure how to look up the record with a generic type.
Thanks in advance!!
View Complete Post