我的.Net 2.5网络表单上有一个<asp:LinqDataSource>
,我正在尝试使用groupby将所有不同的值作为解决问题的“黑客方法”,不能选择不同的。< / p>
按Surname和Forename分组时,我收到一条错误消息:
我的代码是:
<asp:LinqDataSource ID="ldsNewApps" runat="server"
ContextTypeName="siteDBDataContext" OrderBy="Surname" GroupBy="new(Surname, Forename)"
Select="new (staffID, Forename, Surname, City, Country, LastUpdatedDate, tblStaffStatus, Score)"
TableName="tblStaffs" AutoGenerateWhereClause="True" >
答案 0 :(得分:1)
使用group by时,您需要使用aggregate queries来访问对象属性。它还会创建一个名为key
的对象,其值用于分组。
Select="new (max(staffID) as staffID, key.Forename, key.Surname, max(City) as City, max(Country) as Country, max(LastUpdatedDate) as LastUpdatedDate, max(tblStaffStatus) as tblStaffStatus, max(Score) as Score)"
如果您按单个值进行分组,请使用
GroupBy="Surname"
Select="new (key as Surname)"