• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

nhibernate, ICriteria

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?
0
Tina_Bhole
Asked:
Tina_Bhole
  • 2
1 Solution
 
cubaman_24Commented:
Hello:
it would be something like this.
Best regards.
ICriteria criteria = GetBasicCriteria();
criteria.SetProjection(Projections.Max("MyValue"));
return criteria.UniqueResult<int>();

Open in new window

0
 
Tina_BholeAuthor Commented:
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?
0
 
Tina_BholeAuthor Commented:
Oh, I figured it out.
I included the reference: NHibernate.Criterion;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now