Пример #1
0
        public async IAsyncEnumerable <Movie> GetAllMoviesAsyncStreaming()
        {
            var          dbConnection = CreateDbConnection();
            DbCommand    dbCommand    = null;
            DbDataReader dbDataReader = null;

            try
            {
                await dbConnection.OpenAsync().ConfigureAwait(false);

                dbCommand    = CommandFactoryMovies.CreateCommandForGetAllMovies(dbConnection);
                dbDataReader = await dbCommand.ExecuteReaderAsync().ConfigureAwait(false);

                var movie = new Movie();
                while (await dbDataReader.ReadAsync().ConfigureAwait(false))
                {
                    movie.Title    = (string)dbDataReader[0];
                    movie.Genre    = GenreParser.Parse((string)dbDataReader[1]);
                    movie.Year     = (int)dbDataReader[2];
                    movie.ImageUrl = (string)dbDataReader[3];
                    yield return(movie);
                }
            }
            finally
            {
                dbDataReader?.Dispose();
                dbCommand?.Dispose();
                dbConnection.Dispose();
            }
        }
Пример #2
0
        public async Task <IEnumerable <Movie> > GetAllMovies()
        {
            var          dbConnection = CreateDbConnection();
            DbCommand    dbCommand    = null;
            DbDataReader dbDataReader = null;

            try
            {
                await dbConnection.OpenAsync().ConfigureAwait(false);

                dbCommand    = CommandFactoryMovies.CreateCommandForGetAllMovies(dbConnection);
                dbDataReader = await dbCommand.ExecuteReaderAsync().ConfigureAwait(false);

                return(await MapToMovies(dbDataReader));
            }
            finally
            {
                dbDataReader?.Dispose();
                dbCommand?.Dispose();
                dbConnection.Dispose();
            }
        }