Esempio n. 1
0
        IQueryable <TEntity> GetQuery <TEntity>(OrderSpecification <TEntity> orderSpecification, Specification <TEntity> whereSpecification, FetchSpecification <TEntity> fetchSpecification, PaginatedSpecification paginatedSpecification) where TEntity : class, IEntity
        {
            var source = this.session.Value.Query <TEntity>();

            if (whereSpecification != null && whereSpecification.IsSatisfiedBy() != null)
            {
                source = source.Where(whereSpecification.IsSatisfiedBy());
            }

            if (orderSpecification != null)
            {
                var order = new AdHocOrderSpecification <TEntity>();
                orderSpecification.SortedBy()(order);
                source = order.applies.Aggregate(source, (current, apply) => apply(current));
            }

            if (paginatedSpecification != null)
            {
                source = source.Page(paginatedSpecification.CurrentPage, paginatedSpecification.PageSize);
            }

            if (fetchSpecification != null)
            {
                var fetch = new AdHocFetchSpecification <TEntity>();
                fetchSpecification.FetchedBy()(fetch);
                source = fetch.applies.Aggregate(source, (current, apply) => apply(current));
            }

            return(source);
        }
Esempio n. 2
0
        ////ncrunch: no coverage end
        protected bool Equals(AdHocOrderSpecification <TEntity> other)
        {
            if (!this.IsReferenceEquals(other))
            {
                return(false);
            }

            if (this.expressions.Count != other.expressions.Count)
            {
                Console.WriteLine(Resources.AdHocOrderSpecification_Equal_diffrent_count_expressions.F(this.expressions.Count, other.expressions.Count));
                return(false);
            }

            for (int i = 0; i < this.expressions.Count; i++)
            {
                if (!this.expressions[i].Item1.IsExpressionEqual(other.expressions[i].Item1))
                {
                    Console.WriteLine(Resources.AdHocOrderSpecification_Equal_diffrent_expressions.F(this.expressions[i].Item1, other.expressions[i].Item1));
                    return(false);
                }

                if (this.expressions[i].Item2 != other.expressions[i].Item2)
                {
                    Console.WriteLine(Resources.AdHocOrderSpecification_Equal_diffrent_type.F(this.expressions[i].Item2, other.expressions[i].Item2));
                    return(false);
                }
            }

            return(true);
        }
        ////ncrunch: no coverage end
        protected bool Equals(AdHocOrderSpecification <TEntity> other)
        {
            if (!this.IsReferenceEquals(other))
            {
                return(false);
            }

            if (this.expressions.Count != other.expressions.Count)
            {
                return(false);
            }

            for (int i = 0; i < this.expressions.Count; i++)
            {
                if (!this.expressions[i].Item1.IsExpressionEqual(other.expressions[i].Item1))
                {
                    return(false);
                }

                if (this.expressions[i].Item2 != other.expressions[i].Item2)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 4
0
        public static IQueryable <TEntity> Query <TEntity>(this IQueryable <TEntity> source, OrderSpecification <TEntity> orderSpecification, Specification <TEntity> whereSpecification, FetchSpecification <TEntity> fetchSpecification, PaginatedSpecification paginatedSpecification) where TEntity : class, IEntity
        {
            if (whereSpecification.With(r => r.IsSatisfiedBy()) != null)
            {
                source = source.Where(whereSpecification.IsSatisfiedBy());
            }

            if (orderSpecification != null)
            {
                var order = new AdHocOrderSpecification <TEntity>();
                orderSpecification.SortedBy()(order);
                source = order.applies.Aggregate(source, (current, apply) => apply(current));
            }

            if (paginatedSpecification != null)
            {
                source = source.Page(paginatedSpecification.CurrentPage, paginatedSpecification.PageSize);
            }

            if (fetchSpecification != null)
            {
                AdHocFetchSpecificationBase <TEntity> fetch = null;
                string fullName = source.Provider.GetType().FullName;
                if (fullName.EqualsWithInvariant("NHibernate.Linq.DefaultQueryProvider"))
                {
                    fetch = new AdHocFetchNhibernateSpecification <TEntity>();
                }
                else if (fullName.EqualsWithInvariant("System.Data.Entity.Internal.Linq.DbQueryProvider"))
                {
                    fetch = new AdHocFetchEFSpecification <TEntity>();
                }
                else if (fullName.Contains("Raven.Client.Linq.RavenQueryProvider"))
                {
                    fetch = new AdHocFetchRavenDbSpecification <TEntity>();
                }

                if (fetch != null)
                {
                    fetchSpecification.FetchedBy()(fetch);
                    source = fetch.applies.Aggregate(source, (current, apply) => apply(current));
                }
            }

            return(source);
        }
        ////ncrunch: no coverage end
        protected bool Equals(OrderSpecification <TEntity> other)
        {
            ////ncrunch: no coverage start
            if (!this.IsReferenceEquals(other))
            {
                return(false);
            }

            ////ncrunch: no coverage end
            var leftOrder = new AdHocOrderSpecification <TEntity>();

            SortedBy()(leftOrder);

            var rightOrder = new AdHocOrderSpecification <TEntity>();

            other.SortedBy()(rightOrder);

            return(leftOrder.Equals(rightOrder));
        }