This type of situation has always bothered me a bit.
I am building a website in C# 2.0 where users can post reviews of things. Currently I have classes called User, Comment and Review. The Review class inherits from Comment because it is basically a specialized type of Comment.
Now, when I am displaying a list of reviews and comments I need a couple of extra bits of information that are not in the Review or Comments class, e.g. the author's name and avatar.
Keeping performance in mind I make only two queries like this:
SELECT comment.*, user.Name, user.AvatarName FROM comment
INNER JOIN user ON user.UserId = comment.UserId
SELECT review.*, user.Name, user.AvatarName FROM review
INNER JOIN user ON user.UserId = review.UserId
What is the most elegant way to contain this data in c# objects? I'm not particularly fond of exposing raw DataSets to the UI layer. Ideally I want the UI layer to only deal with the c# objects which have been filled in the Data Access Layer.
If I was only getting comment data, I would just create a List of Comment objects. But in this case there is also a small subset of user data to put somewhere.
The options I came up with are:
1) Create a new class with properties for the Comment (or Review), the user's name and the avatar filename.
2) Fill the user's name and and avatar into a User object and just accept that the data is incomplete.
3) Fill the user's name and avatar into the Comment/Review object and expose them as read-only properties.
4) Give up and allow the UI layer to deal with the DataSet directly.
Any thoughts?
I am building a website in C# 2.0 where users can post reviews of things. Currently I have classes called User, Comment and Review. The Review class inherits from Comment because it is basically a specialized type of Comment.
Now, when I am displaying a list of reviews and comments I need a couple of extra bits of information that are not in the Review or Comments class, e.g. the author's name and avatar.
Keeping performance in mind I make only two queries like this:
SELECT comment.*, user.Name, user.AvatarName FROM comment
INNER JOIN user ON user.UserId = comment.UserId
SELECT review.*, user.Name, user.AvatarName FROM review
INNER JOIN user ON user.UserId = review.UserId
What is the most elegant way to contain this data in c# objects? I'm not particularly fond of exposing raw DataSets to the UI layer. Ideally I want the UI layer to only deal with the c# objects which have been filled in the Data Access Layer.
If I was only getting comment data, I would just create a List of Comment objects. But in this case there is also a small subset of user data to put somewhere.
The options I came up with are:
1) Create a new class with properties for the Comment (or Review), the user's name and the avatar filename.
2) Fill the user's name and and avatar into a User object and just accept that the data is incomplete.
3) Fill the user's name and avatar into the Comment/Review object and expose them as read-only properties.
4) Give up and allow the UI layer to deal with the DataSet directly.
Any thoughts?