nhibernate, ICriteria

Posted on 2011-05-11
Last Modified: 2012-05-11
Hi, I am using nhibernate in my web application to interact with my SQL Server database.
and using ICriteria to extract records from the database.
My question is, can I use ICriteria just to extract a single value(eg: Max(Column name)) from database and how can I store it in an integer variable?
Till now, I have been using ICriteria only with IList , but don't know how can I use it to return a single value from the database.
Could someone please help?
Question by:Tina_Bhole
    LVL 8

    Accepted Solution

    it would be something like this.
    Best regards.
    ICriteria criteria = GetBasicCriteria();
    return criteria.UniqueResult<int>();

    Open in new window


    Author Comment

    Thanks for your reply cubaman. I am getting following error on Projections keyword.

    'The name Projection does not exist in current context.

    Am I missing any reference in my project?

    Author Comment

    Oh, I figured it out.
    I included the reference: NHibernate.Criterion;

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now