I have 3 tables (and corresponding entities in the entity model) Game: Id - primay key ... other columns
Player: Id - primary key ... other columns
GamePlayer (a player can participate in many games) GameId --> foreign key from Game PlayerId --> foreign key from Player ... other columns
In my code, I have gameId and playerId available to me thru' other means. Using this I want to know if the player (playerId) is participating in a particular game (gameId). So I'm doing this: (entities is my context object)
IQueryable query = entities.GamePlayer.where(gp => ((gp.Game.Id == gameId) && (gp.Player.Id == playerId))) If the query returns a row, then I know that player is participating in that game.
I read multiple MSDN blogs on entity references and I'm confused. It appears that MSDN recommends that first I have to check the EntityReference object for IsLoaded and if not loaded, I have to load the entity and ONLY then I should use that in the query.
GamePlayer does have GamePlayer.GameReference and GamePlayer.PlayerReference, but I cannot check if reference is loaded because I dont have a GamePlayer object in hand. GamePlayer table holds the two 1...* relationships and thats about it. I have to query GamePlayer only using GameId and PlayerId. What am I doing wrong here?
Should I instead get the Player (or Game) object (using their Ids) and check the GamePlayer entity collection instead? Sql was so simple. If this is so naive, sorry, I'm having a tough time translating my sql query to entity queries.