/// <summary> /// <see cref="Domain.Seedwork.IRepository{TValueObject}"/> /// </summary> /// <param name="specification"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <returns><see cref="Domain.Seedwork.IRepository{TValueObject}"/></returns> public virtual IEnumerable <TEntity> AllMatching(Domain.Seedwork.Specification.ISpecification <TEntity> specification) { var session = _unitOfWork.GetSession(); using (ITransaction transaction = session.BeginTransaction()) { return(session.Query <TEntity>().Where(specification.SatisfiedBy()).ToList()); } }
/// <summary> /// <see cref="IRepository{TEntity}"/> /// </summary> /// <param name="specification"><see cref="IRepository{TEntity}"/></param> /// <returns><see cref="IRepository{TEntity}"/></returns> public virtual IEnumerable <TEntity> AllMatching(Domain.Seedwork.Specification.ISpecification <TEntity> specification) { try { return(GetSet().Where(specification.SatisfiedBy())); } catch (Exception ex) { var ex2 = ex.InnerException as DbEntityValidationException; throw ex; } }
/// <summary> /// <see cref="Domain.Seedwork.IRepository{TValueObject}"/> /// </summary> /// <typeparam name="S"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></typeparam> /// <param name="pageIndex"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <param name="pageCount"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <param name="total"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <param name="orderByExpression"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <param name="ascending"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <param name="specification"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <param name="getTotal"><see cref="Domain.Seedwork.IRepository{TValueObject}"/></param> /// <returns><see cref="Domain.Seedwork.IRepository{TValueObject}"/></returns> public virtual IEnumerable <TEntity> GetPaged <KProperty>(int pageIndex, int pageCount, out int total, System.Linq.Expressions.Expression <Func <TEntity, KProperty> > orderByExpression, bool ascending = true, Domain.Seedwork.Specification.ISpecification <TEntity> specification = null, bool getTotal = true) { IEnumerable <TEntity> query = null; var session = _unitOfWork.GetSession(); total = 0; using (ITransaction transaction = session.BeginTransaction()) { System.Linq.Expressions.Expression <Func <TEntity, bool> > filterByExpression = specification == null ? p => true : specification.SatisfiedBy(); if (ascending) { query = session.Query <TEntity>().Where(filterByExpression) .OrderBy(orderByExpression) .Skip(pageCount * pageIndex) .Take(pageCount) .ToFuture <TEntity>(); } else { query = session.Query <TEntity>().Where(filterByExpression) .OrderByDescending(orderByExpression) .Skip(pageCount * pageIndex) .Take(pageCount) .ToFuture <TEntity>(); } if (getTotal) { var countResult = session.Query <TEntity>().Where(filterByExpression).ToFuture <TEntity>(); total = countResult.Count(); } return(query.ToList <TEntity>()); } }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Domain.Seedwork.IRepository{TValueObject}"/> /// </summary> /// <param name="specification"><see cref="Microsoft.Samples.NLayerApp.Domain.Seedwork.IRepository{TValueObject}"/></param> /// <returns><see cref="Microsoft.Samples.NLayerApp.Domain.Seedwork.IRepository{TValueObject}"/></returns> public virtual IEnumerable <TEntity> AllMatching(Domain.Seedwork.Specification.ISpecification <TEntity> specification) { return(GetSet().Where(specification.SatisfiedBy())); }