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

  • SEARCH
  • Home
  • 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 have users table and want to SELECT some rows by bitmask criteria. I'll
This code selects the first five rows based on the criteria expressed in the
so in my database some rows have NULL values, and when I select *
As we can select multiple rows into single variable declared as some_table.rowtype in SQL.
How can I select some parts of an matrix and cut the single dimensions?
Ran into this error message while trying to select some records off a table.
Can anyone help. Im trying to select some elements on a form but as
I'm inserting multiple rows from one table to another, based on ID. For this
I tried to select the rows based on their ID. For example, in a
I'm trying to update some rows in a table based on two other columns

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.