locked
How do I model this many to one association? RRS feed

  • Question

  • I'm a bit of a loss here.

    Basically I have these two Models:

        public class Player
        {
            public int PlayerId { getset; }
            public string Name { getset; }
     
            public virtual ICollection<GameGames { getset; }
        }
        public class Game
        {
            public int GameId { getset; }
     
            public virtual Player PlayerBlack { getset; }
            public virtual Player PlayerWhite { getset; }
        }

    Now the Database Schema EF Code First creates for me is not correct because the Game table gets 3 Foreign Keys (Playerblack, PlayerWhite and Player) instead of 2.

    So how can I tie these Models together so that EF understands that the Players Games are found by either looking at the Black or White Player.

    Is it even possible?

    Wednesday, March 16, 2011 11:58 PM

Answers