I'm coming from a Java side of using Hibernate and I just haven't found the proper place to put the named query in NHibernate
.
Using Visual Studio 2008 , C# 2008
I have a query
<query name="SchwabAccountList">
from DB_Accounts a
where a.AdminOffCode = 'SWB'
</query>
and I want to put it in the .hbm.xml
for the Account table (DB_Accounts
)
I put it at the end of the file but within the <class>
tag
<query name="AccountList">
from DB_Accounts a
where a.AdminOffCode = 'SWB'
</query>
</class>
</hibernate-mapping>
The code I am using, I have tried several different ways but get
Named query not known: AccountList
or whatever other name I tried to use (assembly.dir.dir.class.queryname
) that sort of thing.
The access code looks like.
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
IList<DB_Accounts> accountList =
(IList<DB_Accounts>)(session.GetNamedQuery("AccountList").List());
foreach (BDM_Controller.Source.ORM.DB_Accounts acctRec in accountList)
{
...
What am I missing?
Thanks,
---John Putnam