I'm struggling with bridging the concepts of good database design with good object orientated design.
Traditionally if I wanted to display a list of news stories in a repeater, I would use something like:
<script runat="server">
void ShowNews()
{
rptNewsStories.DataSource = News.GetAllNews(); // Returns a DataTable
rptNewsStories.DataBind();
}
</script>
<asp:Repeater id="rptNewsStories" runat="server">
<ItemTemplate>
<div>
<span class="Title"><%# Eval("Title")"%> (<%# Eval("Location")"%>)</span>
<p>
<%# Eval("Summary")"%>
</p>
<ul>
<li>Added by: <%# Eval("AddedByFullName")%></li>
<li>Added on: <%# Eval("AddedOn")%></li>
</ul>
</div>
</ItemTemplate>
</asp:Repeater>
Here News.GetAllNews() returns a DataTable, which is just a dump of what the stored procedure returns. The stored procedure is written to return data by using joins, so it's more than one tables worth of data.
The advantage of this in that in the database the stored procedure can look up who added the news story from the AddedByID that exists in the News table and return the persons full name as the AddedByFullName value returned.
However if I try and drop the use of a DataTable and instead return a List of the News objects, I get the following:
<script runat="server">
void ShowNews()
{
rptNewsStories.DataSource = News.GetAllNews(); // Returns a List<News>
rptNewsStories.DataBind();
}
</script>
<asp:Repeater id="rptNewsStories" runat="server">
<ItemTemplate>
<div>
<span class="Title"><%# Eval("Title")"%> (<%# Eval("Location")"%>)</span>
<p>
<%# Eval("Summary")"%>
</p>
<ul>
<li>Added by: <!-- Here there is only a AddedByUserID, not an AddedByFullName value --></li>
<li>Added on: <%# Eval("AddedOn")%></li>
</ul>
</div>
</ItemTemplate>
</asp:Repeater>
But now I'm left with the problem that certain values that I want to display (Like AddedByFullName) don't exist within the News object, because they're not something that's explicitly set, but instead of retrieved from a lookup ID in the object.
I'd like to return objects rather than DataTables, but I don't know the best way to bridge this gap.
Do I:
* Create additional properties in the News class for every additional value that can be returned from the database in relation to this data?
* Stick with DataTables for specific cases where that are lots of additional values?
Or am I just totally on the wrong track!