Often I will want a query that selects from multiple entities to be displayed in a DataGrid. However, I don't want my query to be
SELECT a.Column1, b.Column2, c.Column3, ...
FROM mainEntity a
JOIN relatedEntity1 b,
JOIN relatedEntity2 c, ...
because then I won't get entities back -- I want entities rather than raw values, so that the user can right-click on a grid column and do something with the entity that the column belongs to.
However, if I instead do only
FROM mainEntity a,
JOIN relatedEntity1 b,
JOIN relatedEntity2 c, ...
then I need to know that in the object array returned, the 1st item is a, the 2nd item is b, the 3rd item is c, etc. This is unsatisfactory because I want to be able to specify what entities are being queried, and which properties from those entities to display, independently of each other. Most likely, I will want an option for the user to right-click on the grid header and select "Choose columns" from a context menu at runtime, and properties will be bound/unbound to the grid.
So, I'd like to get an IList of IDictionaries back from the query, instead of just an IList of object[]. Each dictionary would be keyed by the alias used in the query. That way, I can use the aliases from the query to pick which properties to bind to the grid, instead of keeping track of the index numbers of the selected entities.
Of course I could try to convert each object[] into an IDictionary myself, but then I'd have to write an HQL parser to figure out what the aliases are for an arbitrary HQL statement ...
p.s. Since the number of different entities returned by a query would almost certainly be less than 10, the IDictionaries returned should be of type ListDictionary rather than Hashtable ...
|