I have a table called Game
, which holds 4 columns for player id's. And I also have a table called Player
. When I try to count all the games in which a player has been in, I only get the players from the first column in the Game
table.
player.Games.Count();
I have set up foreign keys for all the tables, and it's showing up correctly in the table designer. From the image below, you can see that it should count from blue1+2 and red1+2, but it only counts from Blue1
...
I also tried to create a method to manually select all the games:
public int GetPlayerGames(int playerID)
{
return (from game in db.Games
where game.Blue1 == playerID
|| game.Blue2 == playerID
|| game.Red1 == playerID
|| game.Red2 == playerID
select game).Count();
}
But when I use it inside a linq query
return from player in db.Players
where GetPlayerGames(player.ID) > 0
select player;
I get this error:
Method 'Int32 GetPlayerGames(Int32)' has no supported translation to SQL.