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.
我正在开发一个传统的WebForms项目。在项目中,我正在尝试一些Linq数据源,并计划最终迁移到MVC架构。我对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.
我有一个使用Linq数据源的GridView。我展示的实体有很多关系,我想在关系的许多方面得到一个列的最大值。
I can show properties of the base entity in the gridview:
我可以在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?
有没有办法在tHourlies集合中获取名为WeekEnding的列的最大值以显示在GridView中?
1 个解决方案
#1
Try:
Bind("tJobBase.tJob.tHourlies.Max(w => WeekEnding)")
but I think it would be better to make an specific query wich returns in a field the max value you want, and bind this query to your gridview. Then you could access this field as usual with something like
但我认为最好在字段中返回您想要的最大值的特定查询,并将此查询绑定到gridview。然后你可以像往常一样访问这个字段
Bind("MaxWeekEnding")
#1
Try:
Bind("tJobBase.tJob.tHourlies.Max(w => WeekEnding)")
but I think it would be better to make an specific query wich returns in a field the max value you want, and bind this query to your gridview. Then you could access this field as usual with something like
但我认为最好在字段中返回您想要的最大值的特定查询,并将此查询绑定到gridview。然后你可以像往常一样访问这个字段
Bind("MaxWeekEnding")