Reputation: 97
I'm using Castle ActiveRecord for my project on C# and I have a weird error. I want to retrieve data from one specified column via ActiveRecord methods, so that I could put it into comboBox.
I use this method with simple query:
...
using Castle.ActiveRecord.Queries;
...
public static Lable[] ReturnAllLableNames()
{
SimpleQuery<Lable> q = new SimpleQuery<Lable>(typeof(Lable), @"
Select LableName
from Lable
");
return q.Execute();
}
where Lable is a table and also a class in my project, which has LableID and LableName columns.
The first time I built and tried to run my project, VS asked me to specify the ActiveRecordBaseQuery.cs file, which of course I didn't have, so I pressed "Cancel" and rebuilt my project. The next time I had a following error:
Could not perform ExecuteQuery for Lable
I have no clues where I should search for my error, because I used this code from SimpleQuery examples and I added all necessary references to my class.
On the second thought, is there any other way to retrieve one specified column using Castle AR methods?
I'd be happy to hear any clues regarding my problem.
Upvotes: 1
Views: 1495
Reputation: 99730
NHibernate's HQL, unlike SQL, is case sensitive for properties and class names. In your case, the property is called labelName
, not LabelName
as it says in the query. I recommend changing the property name to LabelName
(see .net design guidelines).
Also, if you're using C# 3.0+ you might want to use auto-implemented properties.
Also, IIRC you need to use fully-qualified properties in the query, e.g. select l.LabelName from Label l
Finally, if you mean to return a list of strings (LabelName
s), you need to change the signature of the method and also use SimpleQuery<string>
instead of SimpleQuery<Label>
. See the SimpleQuery docs for reference.
Upvotes: 2