I’ve got the following model:
An Order has zero or more Order Lines.
Each Order Line may have one Area
For a given order I want to retrieve the area that appears most on its order lines. I currently have a UDF that does this based on the following SQL:
SELECT TOP (1) @Result = [Area].[Area]
FROM [Order] INNER JOIN
[OrderLine] ON [Order].[ OrderId] = [OrderLine].[OrderId] INNER JOIN
[Area] ON [OrderLine].[AreaId] = [Area].[AreaId]
WHERE ([Order].[ OrderId] = @OrderId)
GROUP BY [Area].[Area]
ORDER BY COUNT([Area].[Area]) DESC
How can I convert this to get the AreaEntity in code using my (self servicing) collections / entities?
I suspect I might need to do a GetScalar() on the OrderCollection to get the AreaId, but I’m not sure how to construct the arguments to .GetScalar() to match my sql statement.