Is Product a mapped class? If so, this query,
Quote:
"Select p.Product From PurchaseOrderLine p ..."
will return a list of Product objects (or their proxy). I'm assuming that your datagrid is using automatically generated columns only (if not, please mention what the columns are and what they're bound to), so binding to this list of Products will expose all public properties of Product.
If Product isn't a mapped class, could you post the relevant sections of the PurchaseOrderLine mapping?
Quote:
If i write "Select p.Product....." then one column should be created dynamically in grid and if i write "Select p.Product,p.Price...." two columns should be created dynamically in the grid.
Trying to do that won't work without more effort on your part. Even if NHibernate were to return a sparsely-populated PurchaseOrderLine p object (which it won't with this query), binding a datagrid to that object would still create a column for each public property. If there are multiple items in a select clause, NHibernate will return an
object[] for each row. With "Select p.Product, p.Price", each row returned will be an
object[] of size two with ary[0]=p.Product and ary[1]=p.Price. Trying to bind a datagrid to an array of objects will only expose properties of the
Array class, not the actual data in the array.
One approach would be to have a query "select p from ..." and programmatically hide the columns of the datagrid you aren't using, but that could result in returning a lot more data from the db than necessary. I also don't know if this would work with automatically-generated columns; you may need to specify each column and what it binds to before you can hide them. Another approach would be to use the queries as they're written and use reflection to dynamically create a class that only had the required properties. Then you could loop over the returned rows and assign each object in the array to the correct property of a new instance of the dynamically generated class and bind the datagrid to that list. That would be more difficult to set up, but would only fetch the necessary data from the db. You could also probably do this by implementing the ITypedList interface, but then again you'd need to either get all the data from the DB and hide some of it or iterate over the object arrays returned from the query and putting the data into new instances of PurchaseOrderLine.