views:

274

answers:

2

Hi, I have the following code which works fine. However, I only want to return rows where eventID = 5; Where can I add criteria to this query?

tx = session.BeginTransaction();

        List<Catergory> Catergories;

        using (tx)
        {
            Catergories = (List<Catergory>)session.CreateCriteria(typeof(Catergory)).AddOrder(Order.Asc("catergoryType")).List<Catergory>();

            tx.Commit();
        }

        return Catergories;

Any help much appreciated.

A: 

Tried this but keep getting the following fault;

Catergories = (List<Catergory>)session.CreateCriteria(typeof(Catergory)).Add(Expression.Eq("calEventID",eventID)).AddOrder(Order.Asc("catergoryType")).List<Catergory>();

"Unable to cast object of type 'NHibernate.Impl.QueryImpl' to type 'System.Collections.Generic.List1[Kanpeki.Domain.Catergory]'." message = "faultCode:Server.Processing faultString:'Unable to cast object of type 'NHibernate.Impl.QueryImpl' to type 'System.Collections.Generic.List1[Kanpeki.Domain.Catergory]'.' faultDetail:'null'"enter

+1  A: 

Changed return type List to IList and it worked fine.