예제 #1
0
        public IQueryable <TAggregateRoot> FindAll <TAggregateRoot>(Specifications.ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, Storage.SortOrder sortOrder) where TAggregateRoot : class, IAggregateRoot
        {
            EnsureSession();
            IQueryable <TAggregateRoot> result = null;
            var query = this._session.Query <TAggregateRoot>()
                        .Where(specification.Expression);

            switch (sortOrder)
            {
            case Storage.SortOrder.Ascending:
                if (sortPredicate != null)
                {
                    result = query.OrderBy(sortPredicate);
                }
                break;

            case Storage.SortOrder.Descending:
                if (sortPredicate != null)
                {
                    result = query.OrderByDescending(sortPredicate);
                }
                break;

            default:
                result = query;
                break;
            }

            Commit();
            return(result);
        }
예제 #2
0
        public TAggregateRoot Find <TAggregateRoot>(Specifications.ISpecification <TAggregateRoot> specification) where TAggregateRoot : class, IAggregateRoot
        {
            EnsureSession();
            var result = this._session.Query <TAggregateRoot>().Where(specification.Expression).FirstOrDefault();

            Commit();
            return(result);
        }
예제 #3
0
        public PagedResult <TAggregateRoot> FindAll <TAggregateRoot>(Specifications.ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, Storage.SortOrder sortOrder, int pageNumber, int pageSize) where TAggregateRoot : class, IAggregateRoot
        {
            EnsureSession();
            if (pageNumber <= 0)
            {
                throw new ArgumentOutOfRangeException("pageNumber", pageNumber, "The pageNumber is one-based and should be larger than zero.");
            }
            if (pageSize <= 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, "The pageSize is one-based and should be larger than zero.");
            }
            if (sortPredicate == null)
            {
                throw new ArgumentNullException("sortPredicate");
            }

            var query = this._session.Query <TAggregateRoot>()
                        .Where(specification.Expression);

            int skip       = (pageNumber - 1) * pageSize;
            int take       = pageSize;
            int totalCount = 0;
            int totalPages = 0;
            List <TAggregateRoot>        pagedData = null;
            PagedResult <TAggregateRoot> result    = null;

            switch (sortOrder)
            {
            case Storage.SortOrder.Ascending:
                totalCount = query.ToFutureValue(x => x.Count()).Value;
                totalPages = (totalCount + pageSize - 1) / pageSize;
                pagedData  = query.OrderBy(sortPredicate).Skip(skip).Take(take).ToFuture().ToList();
                result     = new PagedResult <TAggregateRoot>(totalCount, totalPages, pageSize, pageNumber, pagedData);
                break;

            case Storage.SortOrder.Descending:
                totalCount = query.ToFutureValue(x => x.Count()).Value;
                totalPages = (totalCount + pageSize - 1) / pageSize;
                pagedData  = query.OrderByDescending(sortPredicate).Skip(skip).Take(take).ToFuture().ToList();
                result     = new PagedResult <TAggregateRoot>(totalCount, totalPages, pageSize, pageNumber, pagedData);
                break;

            default:
                break;
            }

            Commit();
            return(result);
        }
        public bool Exists(Specifications.ISpecification <TAggregateRoot> specification)
        {
            var count = _efContext.Context.Set <TAggregateRoot>().Count(specification.IsSatisfiedBy);

            return(count != 0);
        }
예제 #5
0
 public void SaveSumResult <TResult>(System.Linq.Expressions.Expression <Func <TEntity, TResult> > selector, Specifications.ISpecification <TEntity> criteria, TResult sum)
 {
 }
예제 #6
0
 public void SaveLongCountResult(Specifications.ISpecification <TEntity> criteria, long count)
 {
 }
예제 #7
0
 public bool TrySumResult <TResult>(System.Linq.Expressions.Expression <Func <TEntity, TResult> > selector, Specifications.ISpecification <TEntity> criteria, out TResult sum)
 {
     sum = default(TResult);
     return(false);
 }
예제 #8
0
 public bool TryLongCountResult(Specifications.ISpecification <TEntity> criteria, out long count)
 {
     count = default(long);
     return(false);
 }
예제 #9
0
 public void SaveCountResult(Specifications.ISpecification <TEntity> criteria, int count)
 {
 }
예제 #10
0
 public bool TryCountResult(Specifications.ISpecification <TEntity> criteria, out int count)
 {
     count = default(int);
     return(false);
 }
예제 #11
0
 public void SaveFindResult <TResult>(Specifications.ISpecification <TEntity> criteria, Repositories.Queries.IQueryOptions <TEntity> queryOptions, System.Linq.Expressions.Expression <Func <TEntity, TResult> > selector, TResult result)
 {
 }
예제 #12
0
 public bool TryFindResult <TResult>(Specifications.ISpecification <TEntity> criteria, Repositories.Queries.IQueryOptions <TEntity> queryOptions, System.Linq.Expressions.Expression <Func <TEntity, TResult> > selector, out TResult result)
 {
     result = default(TResult);
     return(false);
 }