user17510
user17510

Reputation: 1549

NHibernate Query List

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.


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.List
1[Kanpeki.Domain.Catergory]'.' faultDetail:'null'"enter

Upvotes: 0

Views: 848

Answers (1)

user17510
user17510

Reputation: 1549

Changed return type List to IList and it worked fine.

Upvotes: 1

Related Questions