views:

19

answers:

1

I am doing my first nHibernate Join. In my function below, I want to return a list of records for the specified query. Normally my List type is the class representing the database table. In this case, since I am doing a join, I created a custom class that only contains the fields for the columns I am retrieving from the database. However, when I create the Query, I get "ERROR: 42601: syntax error at end of input" which seems to be related to the use of ReportColumns. Can someone tell me if what I am doing is possible, and if not how this can be done?

public IList<ReportColumns> FetchRecords(NHibernateDBConnection db, string MyName)
{
    return db.Session
        .CreateQuery("SELECT s.RunNumber, s.TestStarted, s.StationName, t.Name FROM MyTable1 s, MyTable2 t WHERE (s.RunNumber = t.RunNumber AND t.Name = :MyName")
        .SetParameter("MyName", MyName)
        .List<ReportColumns>();
}
A: 

You are missing the right parenthesis.

Diego Mijelshon
Good eye. I fixed this, but the query is still not accepted. I am getting an exception with:{"The value \"System.Object[]\" is not of type \"MyApp.MyTable+ReportColumns\" and cannot be used in this generic collection.\r\nParameter name: value"}Any other ideas as well?
Ted N
I had overlooked that. You are selecting a list of arbitrary fiels, NHibernate will return that as a List<object[]>. If you need a list of ReportColumn, you need to use a transformer or a Linq-to-objects projection.
Diego Mijelshon