我正在使用带有.net 2.0的亚音速2.2,当我收录“分组依据”时,我遇到了错误。
最初我有这个代码,它运作得很好:
SqlQuery etResourceTitle = new Select(ResTitleOngoing.Columns.ResourceTitleID,
ResTitleOngoing.Columns.ResourceTitle,
VenVendor.Columns.Title,
ResTitleOngoingStatus.Columns.Status).From(Tables.ResTitleOngoing);
etResourceTitle.InnerJoin(ResTitleOngoingStatus.ResourceTitleIDColumn, ResTitleOngoing.ResourceTitleIDColumn);
etResourceTitle.LeftOuterJoin(VenVendor.VendorIDColumn, ResTitleOngoing.VendorIDColumn);
etResourceTitle.OrderAsc(ResTitleOngoing.Columns.ResourceTitle);
etResourceTitle.ExecuteDataSet();
然后我添加了“分组依据”,所以这是我的代码:
SqlQuery etResourceTitle = new Select(Aggregate.GroupBy(ResTitleOngoing.Columns.ResourceTitleID),
Aggregate.GroupBy(ResTitleOngoing.Columns.ResourceTitle),
Aggregate.GroupBy(VenVendor.Columns.Title),
Aggregate.GroupBy(ResTitleOngoingStatus.Columns.Status)).From(Tables.ResTitleOngoing);
etResourceTitle.InnerJoin(ResTitleOngoingStatus.ResourceTitleIDColumn, ResTitleOngoing.ResourceTitleIDColumn);
etResourceTitle.LeftOuterJoin(VenVendor.VendorIDColumn, ResTitleOngoing.VendorIDColumn);
etResourceTitle.OrderAsc(ResTitleOngoing.Columns.ResourceTitle);
etResourceTitle.ExecuteDataSet();
我收到错误:“不明确的列名'ResourceTitleID'。”
执行etResourceTitle.BuildSqlStatement();我得到了:
SELECT ResourceTitleID AS'GroupByOfResourceTitleID', ResourceTitle AS'GroupByOfResourceTitle', 标题AS'GroupByOfTitle', 状态AS'GroupByOfStatus' 来自[dbo]。[RES_TitleOngoing] INNER JOIN [dbo]。[RES_TitleOngoingStatus] ON [dbo]。[RES_TitleOngoing]。[ResourceTitleID] = [dbo]。[RES_TitleOngoingStatus]。[ResourceTitleID] LEFT OUTER JOIN [dbo]。[VEN_Vendor] ON [dbo]。[RES_TitleOngoing]。[VendorID] = [dbo]。[VEN_Vendor]。[VendorID] GROUP BY ResourceTitleID,ResourceTitle,Title,Status 订购ResourceTitle ASC
所以,有人可以帮我解决这个错误。
由于 艾伦
答案 0 :(得分:1)
您的表RES_TitleOngoing和RES_TitleOngoingStatus都包含一个名为ResourceTitleID的列,但您在组中只指定了ResourceTitleID,因此sql server不知道您要分组的ResourceTitleID。
注意:
ResTitleOngoing.Columns.ResourceTitleID
只返回一个字符串“ResourceTitleID”
你应该尝试其中一种:
Aggregate.GroupBy(ResTitleOngoing.ResourceTitleIDColumn)
Aggregate.GroupBy(ResTitleOngoing.Schema.QualifiedName + "."
+ ResTitleOngoing.Columns.ResourceTitleID)