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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:07:35+00:00 2026-05-29T22:07:35+00:00

I have a basic LINQ Query that looks like the following: var results =

  • 0

I have a basic LINQ Query that looks like the following:

var results = from x in context.MyEntities
              where (x.CustomerName != null)
              select new Customer()
              {
                CustomerID = x.CustomerID,
                FirstName = x.FirstName,
                LastName = x.LastName,
                Gender = x.Gender,
                BirthMonth = x.BirthMonth
              };

results = results.GroupBy(x => x.Gender);
results = results.GroupBy(x => x.BirthMonth);

bool onlyShowKnownGenders = GetWhetherToShowOnlySetGenders();
if (onlyShowKnownGenders) {
  results = results.Where(x => ((x.Gender == 1) || (x.Gender == 2)));
}

If I comment out the two “GroupBy” lines, my code works fine. However, I now have a need to group the results. When I include the two “GroupBy” lines, I receive an error that says:

Cannot implicitly convert type ‘System.Linq.IQueryable>’ to ‘System.Linq.IQueryable’. An explicit conversion exists (are you missing a cast?)

My question is, I’m not sure how to do the cast in this case. Can someone please help me out?

Thank you!

  • 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-29T22:07:38+00:00Added an answer on May 29, 2026 at 10:07 pm

    The problem is that after you call a group by you don’t get back an enumerable of (in this case) Customers. You get back an enumerable of groups.

    A group of customers doesn’t have a BirthMonth property.

    What exactly are you trying to do here?

    Is this what you want?

    var results1 = results.GroupBy(x => x.Gender);
    var results2 = results1.Select(group => group.GroupBy(x => x.BirthMonth));
    

    This would give you a group of groups at the end.
    (I also incorporated dasblinkenlight’s answer in that you can’t re-use the same variable since the types are different).

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

Sidebar

Related Questions

I have a basic NHibernate.Linq query: var items = from item in session.Linq<ObjectType>() where
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
I have a very basic XML file that looks like this: <allData> <allDataDetails> <quoteid>ABC123</quoteid>
I have a LINQ query that returns all absences for an employee. The first
I have a basic form with controls that are databound to an object implementing
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic ActiveRecord model in which i have two fields that i
I think I'm missing something really basic. var signatures=from person in db.People where person.Active==true
I have a LINQ-to-SQL data context in which two tables exist with different names
I have a Linq query which I am selecting into a string, of course

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.