I'm trying to join two collections by Id
. Although I can see rows in the database, the query results are empty.
I have two collections: userGames
and games
Here is my Code to join collections:
var userGamesQuery = userGames.AsQueryable()
.Where(x => x.UserId == userId);
var query = from userGame in userGamesQuery
join game in games.AsQueryable() on userGame.GameId equals game.Id
select game;
the first part returns 13 elements but the second part return nothing. I think the line userGame.GameId equals game.Id
has some problems. tried to use ObjectId.Parse()
on both userGame.GameId
and game.Id
but no luck.
Here are my Models
Game Class :
public class Game
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
}
UserGames :
public class UserGames
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string UserId { get; set; }
public string GameId { get; set; }
}