Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get to Foreign keys in the ADO.NET entity model?
    primarykey
    data
    text
    <p>I have 3 tables (and corresponding entities in the entity model) Game: Id - primay key ... other columns</p> <p>Player: Id - primary key ... other columns</p> <p>GamePlayer (a player can participate in many games) GameId --> foreign key from Game PlayerId --> foreign key from Player ... other columns</p> <p>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)</p> <p>IQueryable query = entities.GamePlayer.where(gp => ((gp.Game.Id == gameId) &amp;&amp; (gp.Player.Id == playerId))) If the query returns a row, then I know that player is participating in that game.</p> <p>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.</p> <p>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?</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload