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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:43:35+00:00 2026-05-24T04:43:35+00:00

I have 2 var/objects, retrieving thru these 2 functions: private IQueryable<Project> SelectAll_1(…) { return

  • 0

I have 2 var/objects, retrieving thru these 2 functions:

private IQueryable<Project> SelectAll_1(...)
{
    return query;
}

class Project is:

private int ID;
private string col1;
private string col2;
private string col3;

and another:

private IQueryable<Project_test> SelectAll_2(...)
{
    return query;
}

where POCO of is:

private string ID_inString;
private string col1;
private string col2;
private string col3;

and i need to perform union on both of them,

var P2 = SelectAll_2(...);
var P1 = SelectAll_1(...);

var P3 = P2.Union(P1);

but i get an error, mentioning:

The type arguments for method ‘System.Linq.Queryable.Union(System.Linq.IQueryable, System.Linq.Expressions.Expression>)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

i saw some people solve it thru’ anonymous type, but i not sure how it works. Anyone has any idea?

  • 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-24T04:43:36+00:00Added an answer on May 24, 2026 at 4:43 am

    You can’t union two different types, unless one inherits from the other (for example, you could potentially find a union of IEnumerable<object> and IEnumerable<string>, although that would rarely be useful).

    Now in your case, it sounds like Project and Project_test should really be one type, if the various properties have the same meaning. Currently the ID properties have different types – but is that really necessary or desirable? If they’re both identifiers with the same scope, it makes sense to store them in the same representation. If the properties don’t have the same meaning, you shouldn’t be forming a union between them at all. If they do have the same meaning, you should try to make both sequences use the same type.

    You could use anonymous types for this, in this way:

    var projectedP1 = P1.Select(x => new { x.ID, x.col1, x.col2, x.col3 });
    var projectedP2 = P2.Select(x => new { ID = int.Parse(x.ID_inString),
                                                x.col1, x.col2, x.col3 });
    var union = projectedP1.Union(projectedP2);
    

    Or you could just use one of the existing types:

    var projectedP1 = P1.Select(x => new Project_test { 
                                         ID_inString = x.ID.ToString(), 
                                         col1 = x.col1, 
                                         col2 = x.col2, 
                                         col3 = x.col3 });
    var union = projectedP1.Union(P2);
    

    It’s not really obvious which of these is a better idea – but I’d go back to trying to reconcile the two types if possible, at which point you have no problems anyway.

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

Sidebar

Related Questions

I have a IQueryable<SomePOCO> (a LINQ-Entities query, if that matters): public class SomePOCO {
I have an array of JavaScript objects: var objs = [ { first_nom: 'Laszlo',
I have code similar to this filtering entries in an Array of Objects: var
I have a Linq to objects statement var confirm = from l in lines.Lines
I have an array of objects: var array = [(id, name, value),(id, name, value)];
I have a repository class that uses an NHibernate session to persist objects to
Let's say I have a list of objects: var items = new { new
If I have a reference to an object: var test = {}; that will
I have a javascript that does this (http is your XMLHttpRequest object) var r
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]

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.