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 4124630
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:45:54+00:00 2026-05-20T23:45:54+00:00

Hi Given a list of strings I want to retrieve all items whose names

  • 0

Hi
Given a list of strings I want to retrieve all items whose names contain one of the given strings.
for example- given {“foo”, “kuku”} I want to retrieve the employees “Corfoo”, “kuku maluku” and “kukufoo”.
I’ve tried the following, but got a null-reference exception(?)

query.Where(u => values.Any(v=> u.FullName.Contains(v)) );

The following produced a ‘Lambda expression not in scope’ exception.

query.Where(u => (values.Count(v => u.FullName.Contains(v)) > 0) );

any idea how this can be done?
I was thinking along the lines of iterating over the values collection and adding a new condition for each element.
problem is- the .Where() function is a conjunction (AND) and I need disjunction (OR)…
(I’m using nH 2.1.2 with Linq provider; hadn’t tried this on nH3.0 yet…)

  • 1 1 Answer
  • 2 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. Editorial Team
    Editorial Team
    2026-05-20T23:45:55+00:00Added an answer on May 20, 2026 at 11:45 pm

    If you are not limited to the Linq provider but also open to the ICriteria API, I suggest using the following:

    List<string> fullnames = new List<string>() { "foo", "kuku" };
    // prepare Query
    var query = session.CreateCriteria(typeof(Employee));
    // dynamically add Like-conditions combined with OR
    Disjunction namesCriteria = Restrictions.Disjunction();
    foreach (var name in fullnames)
    {
        namesCriteria.Add(Restrictions.Like("FullName", name, MatchMode.Anywhere));
    }
    // add complete Disjunction to prepared query
    query.Add(namesCriteria);
    IList<Employee> list = query.List<Employee>();
    

    I think trying that in NHibernate.Linq might be harder if not impossible. With NH 3.0 you could use QueryOver, which would get rid of the magic strings.

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

Sidebar

Related Questions

Given a list of strings, I want to sort it alphabetically and remove duplicates.
Given the following simple example: List<string> list = new List<string>() { One, Two, Three,
Given the list ['a','ab','abc','bac'] , I want to compute a list with strings that
I want to search a sorted list of strings for all of the elements
Problem: Given a list of strings, find the substring which, if subtracted from the
Given a dictionary (just a list of strings). You receive a feed of an
Given a list L of n character strings, and an input character string S,
Given a list old_list = [obj_1, obj_2, obj_3, ...] I want to create a
Given a sequence of objects (I'll use strings in this example for simplicity) I'd
I got a list of strings. And I want to check for every string

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.