コード例 #1
0
ファイル: DbLayer.cs プロジェクト: randyammar/LogicMine
        /// <summary>
        /// Retreives the requested T from the database and adds it to the baskets AscendPayload
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetSelectDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false))
            {
                if (!await rdr.ReadAsync().ConfigureAwait(false))
                {
                    throw new InvalidOperationException($"No '{typeof(T)}' record found");
                }

                basket.AscentPayload = Mapper.MapObject(rdr);
            }
        }
コード例 #2
0
ファイル: DbLayer.cs プロジェクト: randyammar/LogicMine
        /// <summary>
        /// Retrieves the requested collection of T's from the database and adds them to the baskets AscendPayload
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IGetCollectionBasket <T> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetSelectDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false))
            {
                var objs = new List <T>();
                while (await rdr.ReadAsync().ConfigureAwait(false))
                {
                    var obj = Mapper.MapObject(rdr);
                    objs.Add(obj);
                }

                basket.AscentPayload = objs.ToArray();
            }
        }