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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:13:52+00:00 2026-06-10T20:13:52+00:00

I want to combine two LINQ query results into one: var query1 = from

  • 0

I want to combine two LINQ query results into one:

var query1 = from sn in code                                        
             group sn by sn.Substring(0, 10) into g
             select new
             {
               Key = g.Key,
               Cnt = g.Count(),
               Min = g.Min(v => v.Substring(10, 4)),
               Max = g.Max(v => v.Substring(10, 4))
             };
var query2 = from sn1 in codes
             group sn1 by sn1.Substring(0, 11) into g
             select new
             {
               key = g.Key,
               Cnt = g.Count(),
               Min = g.Min(v => v.Substring(11, 4)),
               max = g.Max(v => v.Substring(11, 4))
             };
var query3= query1.Union(query2)

but on compilation I get an error:

‘System.Collections.Generic.IEnumerable<AnonymousType#1>‘ does not
contain a definition for ‘Union‘ and the best extension method
overload
‘System.Linq.Queryable.Union<TSource>(System.Linq.IQueryable<TSource>,
System.Collections.Generic.IEnumerable<TSource>)
‘ has some invalid
arguments

what’s wrong with my code?

  • 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-10T20:13:54+00:00Added an answer on June 10, 2026 at 8:13 pm

    In the first query you select to an anonymous type with the properties “Key, Cnt, Min, Max”, in the second you use the properties “key, Cnt, Min, max”. This will result in two different anonymous types, because “Key” is not equal to “key” and “max” is not equal to “Max”. And you can’t use union with two different types.

    Change your second query to this:

                                      select new
                                      {
                                          Key = g.Key,
                                          Cnt = g.Count(),
                                          Min = g.Min(v => v.Substring(11, 4)),
                                          Max = g.Max(v => v.Substring(11, 4))
                                      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to combine two ggplots, from two different data.frames, into one plot. Below
I want to combine these two queries into one: mysql_query(INSERT INTO categories (name, parent)
I want to combine two ArrayList into a single one. My first arraylist looks
Sometimes I want to combine two statements into one to omit curly braces in
I am playing with Parsec and I want to combine two parsers into one
I want to combine two programs into a single executable. One is an open
I'm new to MDX. Now I want to combine two results from 2 different
I'm trying to combine two Google App Engine datastore results. Because I then want
I want to combine two .wav recording files together. Can any one help me
Imagine two positive integers A and B. I want to combine these two into

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.