Ejemplo n.º 1
0
        /// <summary>
        /// Gets all <see cref="IOrder"/>.
        /// </summary>
        /// <param name="keys">
        /// The keys.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IOrder}"/>.
        /// </returns>
        protected override IEnumerable <IOrder> PerformGetAll(params Guid[] keys)
        {
            var dtos = new List <OrderDto>();

            if (keys.Any())
            {
                // This is to get around the WhereIn max limit of 2100 parameters and to help with performance of each WhereIn query
                var keyLists = keys.Split(400).ToList();

                // Loop the split keys and get them
                foreach (var keyList in keyLists)
                {
                    dtos.AddRange(Database.Fetch <OrderDto, OrderIndexDto, OrderStatusDto>(GetBaseQuery(false).WhereIn <OrderDto>(x => x.Key, keyList, SqlSyntax)));
                }
            }
            else
            {
                dtos = Database.Fetch <OrderDto, OrderIndexDto, OrderStatusDto>(GetBaseQuery(false));
            }


            foreach (var dto in dtos)
            {
                var lineItems = GetLineItemCollection(dto.Key);
                var factory   = new OrderFactory(lineItems);
                yield return(factory.BuildEntity(dto));
            }


            //if (keys.Any())
            //{
            //    foreach (var key in keys)
            //    {
            //        yield return Get(key);
            //    }
            //}
            //else
            //{
            //    var dtos = Database.Fetch<OrderDto, OrderIndexDto, OrderStatusDto>(GetBaseQuery(false));
            //    foreach (var dto in dtos)
            //    {
            //        yield return Get(dto.Key);
            //    }
            //}
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a <see cref="IOrder"/> by it's key.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The <see cref="IOrder"/>.
        /// </returns>
        protected override IOrder PerformGet(Guid key)
        {
            var sql = GetBaseQuery(false)
                      .Where(GetBaseWhereClause(), new { Key = key });

            var dto = Database.Fetch <OrderDto, OrderIndexDto, OrderStatusDto>(sql).FirstOrDefault();

            if (dto == null)
            {
                return(null);
            }

            var lineItems = GetLineItemCollection(key);

            var factory = new OrderFactory(lineItems);

            return(factory.BuildEntity(dto));
        }