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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:01:37+00:00 2026-05-20T08:01:37+00:00

I have two queries which return a collection of the same kind of object,

  • 0

I have two queries which return a collection of the same kind of object, after these two queries are done, I want to union them.

var results = from t in All()
              where t.Blah.Contains(blahblah)
              select t;

var results2 = from t in All()
               where t.blah2.contains(blahblah)
               select t;

return results.Union(results2);

It is possible that the second query could return no results, and be null.

It seems like if I try and perform a union with the two, if the second argument is null it will throw an ArgumentNullException.

The obvious answer would be to just to perform .ToList() on the second query to see if it contains anything. The problem with this is I am trying to take advantage of deferred execution and dont want to actually perform the query on the database at this stage.

Is there any way around this?

Edit – Solution

var results2 = from t in All()
        where t.blah2!=null && t.blah2.Contains(blahblah)
        select t;

Basically, the actual query was returning null as I was trying to do a contains on a null list

Thanks for the help!

  • 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-05-20T08:01:38+00:00Added an answer on May 20, 2026 at 8:01 am

    results2 should return an empty list and not null when executing its query. The code you have should not cause any problems and should work just fine in all cases simple cases I can think of. Can you provide input which would cause the problem you are trying to solve?

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

Sidebar

Related Questions

I have the following two queries which I want to get in one query.
I have two seperate queries for my database which return search results for two
I have two MySQL queries which are very similiar however they return a COUNT()
I have two queries which are returning different results when I would expect them
Currently I have two different queries that return exactly the same results however, changing
I have two queries with subqueries for dateparts which I like to join. SELECT
I have a shell script in which I have to execute two queries (on
I have two queries that produce the same columns but different rows. The first
A quick technical question- I have two queries that output some of the same
I have two tables, Tasks and TaskMilestones. I want a query to return the

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.