public bool IsUnique <TModel>(IEntitySpecification <TModel> specification)
            where TModel : PersistentObject
        {
            var inputValueIsUnique = _counter.CountByProperty(specification) == 0;

            return(inputValueIsUnique);
        }
    /// <summary>
    /// 异步规约求值列表。
    /// </summary>
    /// <typeparam name="T">指定的类型。</typeparam>
    /// <param name="queryable">给定的 <see cref="IQueryable{T}"/>。</param>
    /// <param name="specification">给定的 <see cref="IEntitySpecification{T}"/>(可选)。</param>
    /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
    /// <returns>返回一个包含 <see cref="List{T}"/> 的异步操作。</returns>
    public static async Task <IList <T> > EvaluateListAsync <T>(this IQueryable <T> queryable,
                                                                IEntitySpecification <T>?specification = null, CancellationToken cancellationToken = default)
        where T : class
    {
        if (specification is null)
        {
            return(await queryable.ToListAsync(cancellationToken));
        }

        return(await specification.Evaluate(queryable).ToListAsync(cancellationToken));
    }
    /// <summary>
    /// 规约求值列表。
    /// </summary>
    /// <typeparam name="T">指定的类型。</typeparam>
    /// <param name="queryable">给定的 <see cref="IQueryable{T}"/>。</param>
    /// <param name="specification">给定的 <see cref="IEntitySpecification{T}"/>(可选)。</param>
    /// <returns>返回 <see cref="List{T}"/>。</returns>
    public static IList <T> EvaluateList <T>(this IQueryable <T> queryable,
                                             IEntitySpecification <T>?specification = null)
        where T : class
    {
        if (specification is null)
        {
            return(queryable.ToList());
        }

        return(specification.Evaluate(queryable).ToList());
    }
Esempio n. 4
0
        public int CountByProperty <TModel>(IEntitySpecification <TModel> specification) where TModel : PersistentObject
        {
            var property = UINameHelper.BuildNameFrom(specification.PropertyExpression);

            var criteria = GetSession().CreateCriteria(typeof(TModel));

            criteria.Add(Restrictions.Eq(property, specification.Value));

            if (specification.HasExistingId)
            {
                criteria.Add(Restrictions.Not(Restrictions.Eq(PersistentObject.ID, specification.ExistingId)));
            }

            return(criteria.List <TModel>().Count());
        }
    /// <summary>
    /// 规约求值分页列表。
    /// </summary>
    /// <typeparam name="T">指定的类型。</typeparam>
    /// <param name="queryable">给定的 <see cref="IQueryable{T}"/>。</param>
    /// <param name="pageAction">给定的分页动作。</param>
    /// <param name="specification">给定的 <see cref="IEntitySpecification{T}"/>(可选)。</param>
    /// <returns>返回 <see cref="IPagingList{T}"/>。</returns>
    public static IPagingList <T> EvaluatePagingList <T>(this IQueryable <T> queryable,
                                                         Action <IPagingList <T> > pageAction,
                                                         IEntitySpecification <T>?specification = null)
        where T : class
    {
        IPagingList <T> list = new PagingList <T>(queryable);

        if (specification is not null)
        {
            list.Filtrate(query => specification.Evaluate(queryable));
        }

        pageAction(list);

        return(list);
    }
    /// <summary>
    /// 规约求值分页列表。
    /// </summary>
    /// <typeparam name="T">指定的类型。</typeparam>
    /// <param name="queryable">给定的 <see cref="IQueryable{T}"/>。</param>
    /// <param name="pageAction">给定的分页动作。</param>
    /// <param name="specification">给定的 <see cref="IEntitySpecification{T}"/>(可选)。</param>
    /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
    /// <returns>返回一个包含 <see cref="PagingList{T}"/> 的异步操作。</returns>
    public static Task <IPagingList <T> > EvaluatePagingListAsync <T>(this IQueryable <T> queryable,
                                                                      Action <IPagingList <T> > pageAction, IEntitySpecification <T>?specification = null,
                                                                      CancellationToken cancellationToken = default)
        where T : class
    {
        IPagingList <T> list = new PagingList <T>(queryable);

        if (specification is not null)
        {
            list.Filtrate(query => specification.Evaluate(queryable));
        }

        return(cancellationToken.RunTask(() =>
        {
            pageAction(list);

            return list;
        }));
    }
Esempio n. 7
0
        public double Distance(IEntitySpecification item, IMetricItem centroid)
        {
            var sumSquaredDiffs = Math.Pow(item.Height - centroid.Height, 2) + Math.Pow(item.Weight - centroid.Weight, 2);

            return(Math.Sqrt(sumSquaredDiffs));
        }
Esempio n. 8
0
 /// <summary>
 /// 异步查找带有规约的实体分页集合。
 /// </summary>
 /// <typeparam name="TEntity">指定的实体类型。</typeparam>
 /// <param name="pageAction">给定的分页动作。</param>
 /// <param name="specification">给定的 <see cref="IEntitySpecification{TEntity}"/>(可选)。</param>
 /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
 /// <returns>返回一个包含 <see cref="IPagingList{TEntity}"/> 的异步操作。</returns>
 public override Task<IPagingList<TEntity>> FindPagingListWithSpecificationAsync<TEntity>(Action<IPagingList<TEntity>> pageAction,
     IEntitySpecification<TEntity>? specification = null, CancellationToken cancellationToken = default)
     where TEntity : class
     => ReadingEquilizer.InvokeGetLast(a => a.FindPagingListWithSpecificationAsync(pageAction, specification, cancellationToken));
Esempio n. 9
0
 /// <summary>
 /// 查找带有规约的实体分页集合。
 /// </summary>
 /// <typeparam name="TEntity">指定的实体类型。</typeparam>
 /// <param name="pageAction">给定的分页动作。</param>
 /// <param name="specification">给定的 <see cref="IEntitySpecification{TEntity}"/>(可选)。</param>
 /// <returns>返回 <see cref="IPagingList{TEntity}"/>。</returns>
 public override IPagingList<TEntity> FindPagingListWithSpecification<TEntity>(Action<IPagingList<TEntity>> pageAction,
     IEntitySpecification<TEntity>? specification = null)
     where TEntity : class
     => ReadingEquilizer.InvokeGetLast(a => a.FindPagingListWithSpecification(pageAction, specification));
Esempio n. 10
0
 /// <summary>
 /// 查找带有规约的实体集合。
 /// </summary>
 /// <typeparam name="TEntity">指定的实体类型。</typeparam>
 /// <param name="specification">给定的 <see cref="IEntitySpecification{TEntity}"/>(可选)。</param>
 /// <returns>返回 <see cref="IList{TEntity}"/>。</returns>
 public override IList<TEntity> FindListWithSpecification<TEntity>(IEntitySpecification<TEntity>? specification = null)
     where TEntity : class
     => ReadingEquilizer.InvokeGetLast(a => a.FindListWithSpecification(specification));
Esempio n. 11
0
 public int CountByProperty <T>(IEntitySpecification <T> specification) where T : PersistentObject
 {
     Specification = (IEntitySpecification <TModel>)specification;
     return(_count);
 }