예제 #1
0
        public async IAsyncEnumerable <Movie> GetAllMoviesStream()
        {
            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);

                await foreach (var movie in MapToMoviesStreaming(dbDataReader).ConfigureAwait(false))
                {
                    yield return(movie);

                    await Task.Delay(1000);
                }
            }
            finally
            {
                dbDataReader.DisposeIfNotNull();
                dbCommand.DisposeIfNotNull();
                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).ConfigureAwait(false));
            }
            finally
            {
                dbDataReader.DisposeIfNotNull();
                dbCommand.DisposeIfNotNull();
                dbConnection.Dispose();
            }
        }