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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:40:38+00:00 2026-06-07T16:40:38+00:00

I have the NFL season schedule saved in an SQL Server DB. A Game

  • 0

I have the NFL season schedule saved in an SQL Server DB. A Game table has fields of Week (referring to the week of the season in which the game takes place [1-17]), AwayTeamID, and HomeTeamID, among others. The AwayTeamID and HomeTeamID fields are foreign keys referencing the Team table. I want to use a LINQ statement (within an ASP.NET MVC 3 app) to return games by week, including team names from the Team table. I know at least one way to do this, but specifically (and I’m hoping more elegantly), I’d like return a result that has each week associated with a sequence of games that correspond to that week, instead of a returning a sequence of new { Game, AwayTeam, HomeTeam } objects and then drilling into the Game item to get the week. I’m not sure I’ve made my goal clear…if not, let me know and I’ll try to clarify.

I read on 101 LINQ Samples about something similar using the into keyword within a join statement so that the result would be a sequence of weeks, each associated with its own sequence of games. Using the example from that site, I tried the following:

    string[] wks = { "1", "2", "3" };

    var model =
        from g in _db.NFLGames
        join a in _db.NFLTeams on g.AwayTeamID equals a.NFLTeamID
        join h in _db.NFLTeams on g.HomeTeamID equals h.NFLTeamID
        select new TestGameModel { Game = g, AwayTeam = a.Name, HomeTeam = h.Name };

    var weekgames = 
        from w in wks
        join gm in model on w equals gm.Game.NFLWeek into gw
        select new TestNflWeeklySchedule { Week = w, Games = gw };

    foreach (var wg in weekgames) {
        System.Diagnostics.Debug.WriteLine("NFL week: " + wg.Week + "     number of games this week: " + wg.Games.Count());
        foreach (var g in wg.Games) {
            System.Diagnostics.Debug.WriteLine("  " + g.AwayTeam + " at " + g.HomeTeam + " [" + g.Game.DateTimeStart + "]");
        }
    }

The code executes, but the output is

NFL week: 1     number of games this week: 0
NFL week: 2     number of games this week: 0
NFL week: 3     number of games this week: 0

Apparently, the second query joining the model is not matching the games that occur in the designated week. I’ve also tried, instead of two queries, just one LINQ statement, which essentially nests the first query within the second. That gave me the same result.

Can anyone tell me what error I have in my code or why this is not working? I’m new to LINQ, so there’s a good chance it’s something simple.

  • 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-07T16:40:39+00:00Added an answer on June 7, 2026 at 4:40 pm

    Is this what you’re looking for?

    var weekGames = _db.NFLGames.GroupBy(g => g.NFLWeek);
    
    foreach (var wg in weekGames)
    {
        Debug.WriteLine("Week: " + wg.Key + " Games: " + wg.Count());
    
        foreach (var g in wg) 
        {
            Debug.WriteLine(g.AwayTeam + " at " + g.HomeTeam + " [" + g.Game.DateTimeStart + "]");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
Have you ever seen any of there error messages? -- SQL Server 2000 Could
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I currently have the following tests, which look like good candidates for a little
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine

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.