Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 180719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:38:09+00:00 2026-05-11T14:38:09+00:00

If I were to select some rows based on certain criteria I can use

  • 0

If I were to select some rows based on certain criteria I can use ICriterion object in NHibernate.Criterion, such as this:

  public List<T> GetByCriteria()   {   SimpleExpression newJobCriterion =     NHibernate.Criterion.Expression.Eq('LkpStatu', statusObject);   ICriteria criteria = Session.GetISession().CreateCriteria(typeof(T)).SetMaxResults(maxResults);   criteria.Add(newJobCriterion );   return criteria.List<T>();   } 

Or I can use LINQ’s where clause to filter what I want:

  public List<T> GetByCriteria_LINQ()   {    ICriteria criteria = Session.GetISession().CreateCriteria(typeof(T)).SetMaxResults(maxResults);    return criteria.Where(item=>item.LkpStatu=statusObject).ToList();   } 

I would prefer the second one, of course. Because

  1. It gives me strong typing
  2. I don’t need to learn yet-another-syntax in the form of NHibernate

The issue is is there any performance advantage of the first one over the second one? From what I know, the first one will create SQL queries, so it will filter the data before pass into the memory. Is this kind of performance saving big enough to justify its use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:38:10+00:00Added an answer on May 11, 2026 at 2:38 pm

    As usual it depends. First note that in your second snippet there is .List() missing right after return criteria And also note that you won’t get the same results on both examples. The first one does where and then return top maxResults, the second one however first selects top maxResults and then does where.

    If your expected result set is relatively small and you are likely to use some of the results in lazy loads then it’s actually better to take the second approach. Because all entities loaded through a session will stay in its first level cache.

    Usually however you don’t do it this way and use the first approach.

    Perhaps you wanted to use NHibernate.Linq (located in Contrib project ). Which does linq translation to Criteria for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to execute a select and then update some of the rows in
Some databases support commands such as: SELECT TOP 10 START AT 10 * FROM
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have the following query that returns a set of rows based on some
I have rows such as [ISSUE] This is a sample issue [WEBSITE] A bug
This SELECT * FROM SOME_TABLE WHERE SOME_FIELD LIKE '%some_value%'; is slower than this SELECT
I want to be able to make an HTTP call updating some select boxes
Suppose I have a SELECT statement that returns some set of results. Is there
I currently filter some message from my inbox with these steps: select inbox pick
I was reviewing some SQL queries and I saw a select statement that looked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.