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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:17:28+00:00 2026-06-13T23:17:28+00:00

I need some help in building the correct query. I have an Employees table.

  • 0

I need some help in building the correct query. I have an Employees table. I need to get a list of all employees, that EENO (Employee ID) contains a string from a supplied array of partial Employee IDs.

When I use this code

// IEnumerable<string> employeeIds is a collection of partial Employee IDs
IQueryable<Employee> query = Employees;
foreach (string id in employeeIds)
{
    query = query.Where(e => e.EENO.Contains(id));
}
return query;

I will get something like:

SELECT * 
FROM Employees 
WHERE EENO LIKE '%1111111%' 
  AND EENO LIKE '%2222222%' 
  AND EENO LIKE '%3333333%' 
  AND EENO LIKE '%4444444%' 

Which doesn’t make sense.
I need “OR” instead of “AND” in resulting SQL.

Thank you!

UPDATE

This code I wrote using PredicateBuilder works perfectly when I need to include these employees.

var predicate = PredicateBuilder.False<Employee>();
foreach (string id in employeeIds)
{
    var temp = id;
    predicate = predicate.Or(e => e.EENO.Contains(temp));
}
var query = Employees.Where(predicate);

Now, I need to write an opposite code, to exclude these employees,
here it is but it is not working: the generated SQL is totally weird.

var predicate = PredicateBuilder.False<Employee>();
foreach (string id in employeeIds)
{
    var temp = id;
    predicate = predicate.And(e => !e.EENO.Contains(temp)); // changed to "And" and "!"
}
var query = Employees.Where(predicate);
return query;

It’s supposed to generate SQL Where clause like this one:

WHERE EENO NOT LIKE '%11111%'
       AND NOT LIKE '%22222%'
       AND NOT LIKE '%33333%'

But it’s not happening

The SQL generated is this: http://i.imgur.com/9MDP7.png

Any help is appreciated. Thanks.

  • 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. Editorial Team
    Editorial Team
    2026-06-13T23:17:29+00:00Added an answer on June 13, 2026 at 11:17 pm

    I’d take a look at http://www.albahari.com/nutshell/predicatebuilder.aspx. This has a great way of building Or queries, and is written by the guy that wrote LinqPad. The above link also has examples of usage.

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

Sidebar

Related Questions

I need some help building an Query. I have a table Orders with 3
Need some help with a query.. I have three tables. Source id name 1
Need some help with DataFormatString in GridView. I have a Double value that needs
Hey. I urgently need some help on building up a complete table using VBA.
I need some help building a table(s) for a music database in MySQL. I
I'm building a simple review website application and need some help with SQL Query.
I am building a form where I have some elements that need to appear
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview

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.