Accepting some aggregate functions in linq datasource in GridView

I am working on a traditional WebForms project. In a project I am testing some Linq data sources with plans to move to MVC architecture. I am still very new to Linq.

I have a GridView using Linq datasource. The entities I am showing have many relationships and I would like to get the maximum value of a column across many sides of the relationship.

I can show the properties of the underlying object 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 many related properties:

<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 maximum value of the column named WeekEnding in the tHourlies collection to display in the GridView?

0


a source to share


1 answer


Try:

Bind("tJobBase.tJob.tHourlies.Max(w => WeekEnding)")

      



but i think it would be better to make a specific query that returns the maximum value you want in the field and bind that query to your gridview. Then you can access this field as usual with

Bind("MaxWeekEnding")

      

0


a source







All Articles