Acceessing some aggregate functions in a linq datasource in a GridView
- by Stephen Pellicer
I am working on a traditional WebForms project. In the project I am trying out some Linq datasources with plans to eventually migrate to an MVC architecture. I am still very new to Linq.
I have a GridView using a Linq datasource. The entities I am showing has a to many relationship and I would like to get the maximum value of a column in the many side of the relationship.
I can show properties of the base entity in the gridview:
<asp:TemplateField HeaderText="Number" SortExpression="tJobBase.tJob.JobNumber">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("tJobBase.tJob.JobNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
I can also show the count of the many related property:
<asp:TemplateField HeaderText="Number" SortExpression="tJobBase.tJob.tHourlies.Count">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("tJobBase.tJob.tHourlies.Count") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
Is there a way to get the max value of a column called WeekEnding in the tHourlies collection to show in the GridView?