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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:50:35+00:00 2026-05-23T15:50:35+00:00

I am trying to combine (union or concat) two lists/collection into one. The two

  • 0

I am trying to combine (union or concat) two lists/collection into one. The two lists have a common base class. e.g. I’ve tried this:

        IQueryable<ContractItem> contractItems = myRepository.RetrieveContractItems();
        IQueryable<ChangeOrderItem> changeOrderItems = myRepository.RetrieveChangeOrderItems();

        IQueryable<ItemBase> folderItems = contractItems.Concat<ItemBase>(changeOrderItems);

But am getting the LINQ error
DbUnionAllExpression requires arguments with compatible collection ResultTypes.

Anybody know how to do this properly? The only thing I could google was another StackOverflow question:
LINQ Union objects with same Base Class

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-05-23T15:50:36+00:00Added an answer on May 23, 2026 at 3:50 pm

    Use the Cast operator:

    IQueryable<ItemBase> folderItems = contractItems
            .Cast<ItemBase>()
            .Concat(changeOrderItems.Cast<ItemBase>());
    

    The answer to the other question works for LINQ to Objects, but not necessarily for LINQ to Entities or LINQ to SQL.

    Alternatively, you can convert to LINQ to Objects by calling AsEnumerable:

    IQueryable<ItemBase> folderItems = contractItems
            .AsEnumerable()
            .Concat<ItemBase>(changeOrderItems);
    

    However, take care in LINQ to Objects; Concat would work without any overhead (iterating through both collections from the database), but Union would pull one of the collections entirely from the database and then iterate through the other.

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

Sidebar

Related Questions

I am trying to combine two images into one. This is the code I
im trying to combine two images into a single image. unfortunately this has to
I am trying to combine the following two functions into one portable function: void
I'm trying to combine two photos into one image (think a body with a
I'm trying to combine a list of functions like so. I have this: Func<int,
I'm trying to combine 2 different regex with the same names into one and
I'm trying to combine multiple JSON objects into a single one in PHP. I'm
I have the following two mysql queries and I am trying to combine them
So I have been trying to combine the answers of these two questions: C#
I am trying to combine the two into a single statment, I would even

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.