I've been using SQL Server for almost a decade now and I've never seen this error before... The SQL generated by NHIbernate is valid, and should work, but SQL Server for some reason just doesn't like it.
The HQL is:
Code:
SELECT Product FROM Product AS Product LEFT OUTER JOIN Product.MainCategory AS Category INNER JOIN Product.Manufacturer AS Manufacturer ORDER BY Manufacturer.Name, Category.FullName, Product.Name
The generated SQL is:
Code:
select top 5
product0_.Uid as Uid,
product0_.AvailableOn as Availab11_,
product0_.Name as Name,
product0_.Price as Price,
product0_.Manufacturer as Manufact6_,
product0_.ModelNumber as ModelNum7_,
product0_.ImageThumbnailUrl as ImageTh14_,
product0_.MainCategory as MainCate5_,
product0_.Version as Version,
product0_.Weight as Weight,
product0_.Description as Descript4_,
product0_.ImageUrl as ImageUrl,
product0_.Notes as Notes,
product0_.Dimension as Dimension,
product0_.Url as Url
from SevenCamels_Applications_ScrappyCamel_BusinessObjects_Product product0_
left outer join SevenCamels_Applications_ScrappyCamel_BusinessObjects_Category category1_
on product0_.MainCategory=category1_.Uid
inner join SevenCamels_Applications_ScrappyCamel_BusinessObjects_Manufacturer manufactur2_
on product0_.Manufacturer=manufactur2_.Uid
order by manufactur2_.Name , category1_.FullName , product0_.Name
The error thrown by SQL Server is:
"A column has been specified more than once in the order by list. Columns in the order by list must be unique."
I believe it's because the product0_.Name column has been given the Name alias. SQL Server sees two Name columns in the ORDER BY clause and freaks out, even though they're both qualified and different. If I take out the alias for the product0_.Name column, the SQL works fine (just in Query Analyzer). It's a bug that's been noted before in the
LLBLGen forums. Has anyone seen it before and managed to come up with a fix or workaround?