0

I'm using Subsonic 2.1 and I'm having an error with the next query:

SqlQuery queryResTitle = new Select(
    new Aggregate(ResTitle.ResourceTitleIDColumn, "ResourceTitleID", AggregateFunction.GroupBy),
    new Aggregate(ResTitle.ResourceTitleColumn, "ResourceTitle", AggregateFunction.GroupBy),
    new Aggregate(VenVendor.TitleColumn, "Title", AggregateFunction.GroupBy),
    new Aggregate(ResTitleStatus.StatusColumn, "Status", AggregateFunction.GroupBy))
  .From(Tables.ResTitleOngoing)
  .InnerJoin(ResTitleStatus.ResourceTitleIDColumn, ResTitle.ResourceTitleIDColumn)
  .LeftOuterJoin(VenVendor.VendorIDColumn, ResTitle.VendorIDColumn);

I'm getting the error:

"The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified"

I also added .Top("1") but I still got the same error.

2
  • How is ResTitleOngoing linked with the other tables? Looks like there's a join missing. Though I still don't see where the ORDER BY is coming from - can you post the generated SQL?
    – marapet
    Jun 21, 2011 at 11:58
  • What database are you using? (add it to the tags) Jun 22, 2011 at 12:47

1 Answer 1

1

You should debug the generated query that SubSonic returns:

var queryString = queryResTitle.BuildSqlStatement();

and execute it in your favorite database administration tool. Maybe you can figure out what's going wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.