I am working on a rather large MongoDB database and wondering if there is a more efficient way for some queries. For example, I store many instances Game
in db, where the class Game
looks like this:
public class Game{
[BsonId]
public long ID { get; set; }
public List<Player> Players { get; set; }
}
where each instance of the game has a list Player
, which, in turn, has some properties, such as Name
.
In one presentation model, I want to bind ComboBox
all the players in the database to the name, but remember that the same player could play many games. I load them as follows:
private void LoadPlayersNames() {
var _l = StaticMongo.GetGames.SelectMany(n => n.Players).Select(n => n.Name);
PlayerNames = new ObservableCollection<string>(new HashSet<string>(_l));
}
StaticMongo
MongoClient
IMongoDatabase
, GetGames
StaticMongo
:
private readonly static IMongoDatabase _database;
public static IMongoQueryable<DetailedHand> GetGames {
get {
return _database.GetCollection<Game>("Games").AsQueryable();
}
}
, , :
1: ( HashSet
), .
2: MongoDB AsQueryable ?
, , , .