public IEnumerable <IGameDetails> ReadAll() { return(_appDatabaseProvider.TransactionalSqlQuery <IEnumerable <IGameDetails> >((db, transaction) => { // TODO: do inner join it is faster, but it makes the implementation more complicated. var selectGames = "SELECT * FROM Game"; var selectCategories = "SELECT * FROM GameCategory WHERE GameId = @Id"; var games = db.Query <GameDetails>(selectGames, transaction: transaction).AsList(); foreach (var game in games) { var categories = db.Query <GameCategory>(selectCategories, new { game.Id }, transaction); game.Categories = categories; } return games; })); }
public IEnumerable <IUserProfile> ReadAll() { return(_appDatabaseProvider.TransactionalSqlQuery <IEnumerable <IUserProfile> >((db, transaction) => { var selectProfiles = "SELECT * FROM Profile"; var selectUser = "******"; var profiles = db.Query <UserProfile>(selectProfiles, transaction: transaction).AsList(); foreach (var profile in profiles) { var user = db.QueryFirstOrDefault <UserDetails>(selectUser, new { Id = profile.UserId }, transaction); var game = _gamesProvider.ReadById(profile.GameId); profile.User = user; profile.Game = game; } return profiles; })); }