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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:07:36+00:00 2026-05-22T16:07:36+00:00

I’m hitting a loss at how to approach this problem. I am writing a

  • 0

I’m hitting a loss at how to approach this problem. I am writing a function where I want the return type to be:

Dictionary(Of String, Dictionary(Of Integer, List(Of Article)))

I’ve basically got a list of articles that I wanted grouped by semester name, then by month value, then by the list of articles that fit into that.

So far I have been able to do this:

Dim lectures As New Dictionary(Of Integer, List(Of Article))
        lectures = (From Articles In db.Articles _
           Order By Articles.StartDate.Value.Month Ascending _
           Where Articles.ArtType = ArticleConstants.lecturesTypeId _
           Group By Articles.StartDate.Value.Month _
           Into Group).AsEnumerable().Reverse.ToDictionary(Function(x) x.Month, Function(x) x.Group.ToList())

And this gets me the inner dictionary, however I am not sure where to go from here. Since I am only storing the month as an integer, I can’t use that to reliably determine the semester (as a semester is “Fall 2011”). I also can’t grab the full date because then my grouping wouldn’t work.

I have a service to get the semester based on the Article’s startDate that looks like this:

SemesterService.getSemester(Article.StartDate)

But again I am not sure how to apply this. I am thinking maybe I just start with all the articles in a given date range and then manually populate both the inner and outer dictionaries based on some logic which iterates through those results, but I have never done something this complex before and I am having trouble.

So in the end I would have a result set that looks like:

Fall 2011 (outer dictionary key)
    1 (for January, inner dictionary key)
        Article 1
        Article 2 (list of articles, inner dictionary value)
        Article 3

Can anyone help me out?

EDIT: I am open to using a different return type, as long as it nests and groups data in a similar fashion.

Semester is NOT an object stored in the database at all. It’s just a static object I populate based on the date, so I cannot query by that. I just have my articles in the database, which has a startdate associated with it, and using that startdate I can calculate the semester it’s in.

Edit: Tried usr’s solution below which is:

From Articles In db.Articles _
   Order By Articles.StartDate.Value.Month Ascending _
   Where Articles.ArtType = ArticleConstants.lecturesTypeId _
   Group New With { Articles, .Semester = SemesterService.getSemester(Articles.StartDate) } By Articles.StartDate.Value.Month _
   Into Group

Upon doing this I get an error: LINQ to Entities does not recognize the method 'Semester getSemester(System.DateTime)' method, and this method cannot be translated into a store expression.

It just seems to really hate grouping by something you calculate in the query but isn’t in the original dataset.

  • 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-22T16:07:37+00:00Added an answer on May 22, 2026 at 4:07 pm

    I will answer in pseudo-C#:

    from s in semesters
    group s by s.Name into g
    select new {
     SemName = g.Key,
     MonthsItems = (from y in g group y by y.Month into g2 select new { Month = g2.Key, ... }
    }
    

    This is how you do a nested grouping. However! This will yield depressingly bad perf. Be sure do replace “semesters” with “semesters.AsEnumerable()” to cause the nested grouping to be evaluated on the client. SQL does not have the ability to return trees so this cannot be done on the server. Hope this helps, if unclear, comment and I will elaborate.

    As an alternative, do this:

    from s in semesters
    group s by new { s.Name, s.Month }
    

    That way you can execute fully on the server.

    Edit: From the comments I can tell the problem is something different.

           From Articles In db.Articles _
           Order By Articles.StartDate.Value.Month Ascending _
           Where Articles.ArtType = ArticleConstants.lecturesTypeId _
           Group new { Articles, Semester = SemesterService.getSemester(Articles.StartDate) } By Articles.StartDate.Value.Month _
           Into Group
    

    Notice that the group by feature allows to to have two paramters not one. You can not only specify the grouping columns but also the values you want to have in each group. In this case I specified to group by month not only the articles but to also retain their semesters. Jope this helps.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.