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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:56:54+00:00 2026-06-15T23:56:54+00:00

I have a query like below. anyone have idea why the ?: parts are

  • 0

I have a query like below. anyone have idea why the ?: parts are always return false values although there is item contains in LIST. Or anyone have better idea to write this query, feel free to reply here. thanks.

List EList = new List();
EList.Add(new EmployeeInfo(1, "a1", "b1"));
EList.Add(new EmployeeInfo(2, "a2", "b2"));
List OList = new List();
OList.Add(new EmployeeInfo(1, "a1", "b1"));
OList.Add(new EmployeeInfo(2, "a2", "b2"));
OList.Add(new EmployeeInfo(3, "aa2", "bb2"));

var results = (
    from e in b
    select new
    {
        Id = e.ID,
        Name = e.Name,
        Email = e.Email,
        IS_Elist = (EList.Contains(e))?true:false,
        IS_Olist = (OList.Contains(e)) ? true : false,
    }
    ).ToList();
  • 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-15T23:56:55+00:00Added an answer on June 15, 2026 at 11:56 pm

    First you can simplify your query – expression ? : true : false is equivalent to just expression and we get the following.

    var results = b.Select(e => new
                                {
                                    Id = e.ID,
                                    Name = e.Name,
                                    Email = e.Email,
                                    IS_Elist = EList.Contains(e),
                                    IS_Olist = OList.Contains(e)
                                 })
                   .ToList();
    

    This should and will definitely yield true if an item from b is contained in EList or OList. If you always get false this means that EList and OList do not contain any items from b. Remember that you are probably doing a comparison of references and therefore

    new EmployeeInfo(1, "a", "b") == new EmployeeInfo(1, "a", "b")
    

    will usually yield false.

    I guess you actually intended a comparison by ID.

    var results = b.Select(e => new
                                {
                                    Id = e.ID,
                                    Name = e.Name,
                                    Email = e.Email,
                                    IS_Elist = EList.Any(x => x.ID == e.ID),
                                    IS_Olist = OList.Any(x => x.ID == e.ID)
                                 })
                   .ToList();
    

    The alternative solution is to implement IEquatable<T> on EmployeeInfo or overriding Equals(), GetHashCode() and the equality operator. You should take care that all your implementations yield consistent results or you will end with a lot of confusion why for example Object.Equals() and the equality operator yield different results.

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

Sidebar

Related Questions

I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
I have a result from a query like the below, which does not have
I have sql query like shown below the sql server says that their is
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query like: SELECT ... FROM ... WHERE .. AND SomeID =
I have a query like DELETE from tablename where colname = value; which takes
I have a query like so : SELECT * FROM table WHERE premium =
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have an query like: SELECT id as OfferId FROM offers WHERE concat(partycode, connectioncode)

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.