3
votes

I am having problems with my HQL query bellow:

var merchantTransactions = session.CreateQuery("SELECT MS.Transaction "+
                                               "FROM MerchantSite AS MS "+
                                               "INNER JOIN MS.Transaction AS MST"+
                                               "WHERE MS.Site.Name = :merchantName");

Then I set parameters like this:

merchantTransactions.SetParameter("merchantName", merchantName);

And it gives me a "could not locate named parameter" error, any ideas why?

merchantName does exist in this context and all the table names are correct.

2

2 Answers

12
votes

You are missing a space between MST and WHERE.

0
votes

You have to use methods to create an HQL statment using a fluent interface style. Try something like this:

var merchantTransactions = session.CreateQuery("SELECT MS.Transaction "+
                                               "FROM MerchantSite AS MS "+
                                               "INNER JOIN MS.Transaction AS MST"+
                                               "WHERE MS.Site.Name = :merchantName")
                                  .SetParameter("merchantName", merchantName);

Or

merchantTransactions = merchantTransactions.SetParameter("merchantName", merchantName);

And do not forget to call a method to concrete your query.

  var result = merchantTransactions.List<Entity>();