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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:21:52+00:00 2026-06-04T14:21:52+00:00

Im trying to use LINQ to sort data that is going to be used

  • 0

Im trying to use LINQ to sort data that is going to be used into a report. The report strucuture looks like this:


Developer name

Date | Hours | Project Name | Week Ending
Date | Hours | Project Name | Week Ending
Date | Hours | Project Name | Week Ending

Developer name

Date | Hours | Project Name | Week Ending
Date | Hours | Project Name | Week Ending

Developer name

Date | Hours | Project Name | Week Ending
Date | Hours | Project Name | Week Ending
Date | Hours | Project Name | Week Ending


I am bringing all that data from a .dbml file. For such sorting i have this linq query:

DataClasses1DataContext context = new DataClasses1DataContext();
        System.Data.Linq.ISingleResult<s_SummaryReportResult> res = context.s_timesheet_SummaryReport(startDate, endDate);

        var orb = from c in res
                  group c by c.developer
                  into devgroup
                  select new 
                  {   
                      Dev = devgroup.Key,
                      devData = from o in res
                                      select new {
                                        o.Date,
                                        o.Hours,
                                        o.projectname,
                                        o.week_ending
                                      }};

IDictionary dic_orb = orb.ToDictionary(result => result.Dev.ToString(), result => result.devData);


        foreach (KeyValuePair<string, object> item in dic_orb)
        {
          object brr =  item.Value;
        }

Sadly, on the foreach step i get an “InvalidCastException”.

Any clues in how i can resolve that foreach, or in a sense, how to group better that LINQ query?

Thanks in advance.

  • 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-04T14:21:54+00:00Added an answer on June 4, 2026 at 2:21 pm

    dic_orb is a Dictionary<string, IEnumerable<'a>> where 'a is the anonymous type defined in your query. The type KeyValuePair<string, IEnumerable<'a>> is not convertible to KeyValuePair<string, object> hence the invalid cast. The fix is to declare item using var in your foreach loop:

    foreach (var item in dic_orb)
    {
        object brr =  item.Value;
    }
    

    Since item.Value is an IEnumerable<'a> you can iterate it using

    var brr = item.Value;
    foreach(var b in brr)
    {
    }
    

    If you just want to iterate all nested collections you can use

    foreach(var b in dic_orb.SelectMany(kvp => kvp.Vaue))
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use LINQ to return a list of tasks that are
I'm trying to get this sitemap clas s working. It appears to use LINQ,
I'm trying to use LINQ To Objects to create a query that will give
Hi all i'm struggling a bit with trying to use Linq to extract data
I am trying to use LINQ to retrieve some data from a dictionary. var
I'm trying to use LINQ to bind the data in my GridView. In my
I'd like ask a question about building applications in .NET that use data from
Spent all day trying to find ready to use solution for Sort data in
I'm trying to use Linq to pivot a data table. Trawling through the responses
I'm trying to do some conversion and would like to use Linq to achieve

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.