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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:12:23+00:00 2026-06-17T17:12:23+00:00

I am working on a simple MVC application using Entity Framework to track the

  • 0

I am working on a simple MVC application using Entity Framework to track the scores of a Badminton league. I have the following two classes:

public class Game
{
    public int Id { get; set; }
    public Player Player1 { get; set; }
    public Player Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

and

public class Player
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
    public List<Game> Games { get; set; }
}

The problem I have is when I have an instance of a player the Games property is returning an empty list. When I request my list of players I use the following:-

var players = badmintonDB.Players.Include("Games").ToList();

From a search on SO I have attempted to override OnModelCreating. I have tried the following with and without the Map(). This creates another table in my database but it doesn’t contain any records.

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Player>().HasMany(p => p.Games).WithMany()
            .Map(m =>
            {
                m.ToTable("PlayerGames");
                m.MapLeftKey("Player_Id");
                m.MapRightKey("Game_Id");
            });

        base.OnModelCreating(modelBuilder);

    }

I cannot see where I am going wrong, whether I need to rethink the design of my POCO’s or if I have the syntax wrong when overriding OnModelCreating.

Any help would be appreciated.

  • 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-17T17:12:25+00:00Added an answer on June 17, 2026 at 5:12 pm

    I’m not sure if that design can work the way you want it to. What if you made a new “Score” entity to tie players to games like so:

    public class Game
    {
        public int Id { get; set; }
        public virtual ICollection<Score> Scores { get; set; }
    }
    
    public class Player
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string Surname { get; set; }
        public virtual ICollection<Score> Scores { get; set; }
    }
    
    public class Score
    {
        public int ScoreId { get; set; }
        public virtual  Player Player { get; set; }
        public virtual Game Game { get; set; }
        public int Score { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple test application using asp.net mvc with C#. The application
I am working on a simple blog application using MVC 4 and the new
Im working on a what I thought would be simple application using zend framework.
Good Day, I have a simple working routine in Perl that swaps two words:
I have been using Entity Framework CTP with Code-First as in this tutorial by
I am using Spring MVC for a web application and I am working with
I am working on my second CI application. I have created some simple CRUD
I'm working on an asp.net MVC application. I have a class that wraps a
I'm new to Entity Framework and MVC 4, and I've been following the Music
I've got a simple web application using ASP.NET MVC3 and Ninject.Web.MVC (the MVC3 version).

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.