Example #1
0
        /// <summary>
        /// Execute LINQ query and fill a result.
        /// </summary>
        /// <typeparam name="T">Model type</typeparam>
        /// <param name="instanz">The instanz.</param>
        /// <param name="constraints">The constraints.</param>
        /// <returns>Search reuslt</returns>
        public static IQueryResult <T> ToSearchResult <T>(this IQueryable <T> instanz, IQueryConstraints <T> constraints)
            where T : class
        {
            if (instanz == null)
            {
                throw new ArgumentNullException("instanz");
            }
            if (constraints == null)
            {
                throw new ArgumentNullException("constraints");
            }

            var totalCount   = instanz.Count();
            var limitedQuery = constraints.ApplyTo(instanz);

            return(new QueryResult <T>(limitedQuery, totalCount));
        }
Example #2
0
        /// <summary>
        /// Execute LINQ query and fill a result.
        /// </summary>
        /// <typeparam name="TFrom">Database Model type</typeparam>
        /// <typeparam name="TTo">Query result item type</typeparam>
        /// <param name="instanz">The instanz.</param>
        /// <param name="constraints">The constraints.</param>
        /// <param name="converter">Method used to convert the result </param>
        /// <returns>Search reuslt</returns>
        public static IQueryResult <TTo> ToSearchResult <TFrom, TTo>(this IQueryable <TFrom> instanz,
                                                                     IQueryConstraints <TFrom> constraints,
                                                                     Func <TFrom, TTo> converter) where TFrom : class
            where TTo : class
        {
            if (instanz == null)
            {
                throw new ArgumentNullException("instanz");
            }
            if (constraints == null)
            {
                throw new ArgumentNullException("constraints");
            }

            var totalCount   = instanz.Count();
            var limitedQuery = constraints.ApplyTo(instanz);

            return(new QueryResult <TTo>(limitedQuery.Select(converter), totalCount));
        }
        /// <summary>
        /// Execute LINQ query and fill a result.
        /// </summary>
        /// <typeparam name="T">Model type</typeparam>
        /// <param name="dbQuery">The dbQuery.</param>
        /// <param name="constraints">The constraints.</param>
        /// <returns>Search result</returns>
        public static IQueryResult <T> ToSearchResult <T>(this DbQuery <T> dbQuery, IQueryConstraints <T> constraints)
            where T : class
        {
            if (dbQuery == null)
            {
                throw new ArgumentNullException(nameof(dbQuery));
            }

            if (constraints == null)
            {
                throw new ArgumentNullException(nameof(constraints));
            }

            int totalCount = constraints.Predicate == null
                                ? dbQuery.Count()
                                : dbQuery.Count(constraints.Predicate);

            List <T> limitedQuery = constraints.ApplyTo(dbQuery).ToList();

            return(new QueryResult <T>(limitedQuery, totalCount));
        }
Example #4
0
        /// <summary>
        /// Execute LINQ query and fill a result.
        /// </summary>
        /// <typeparam name="T">Model type</typeparam>
        /// <param name="dbQuery">The dbQuery.</param>
        /// <param name="constraints">The constraints.</param>
        /// <returns>Search result</returns>
        public static IQueryResult <T> ToSearchResult <T>(this DbQuery <T> dbQuery, IQueryConstraints <T> constraints)
            where T : class
        {
            if (dbQuery == null)
            {
                throw new ArgumentNullException("dbQuery");
            }

            if (constraints == null)
            {
                throw new ArgumentNullException("constraints");
            }

            var totalCount = constraints.Predicate == null
                                ? dbQuery.Count()
                                : dbQuery.Count(constraints.Predicate);

            var limitedQuery = constraints.ApplyTo(dbQuery).ToList();

            return(new QueryResult <T>(limitedQuery, totalCount, constraints.PageNumber, constraints.PageSize));
        }
        /// <summary>
        /// Execute LINQ query and fill a result.
        /// </summary>
        /// <typeparam name="TFrom">Database Model type</typeparam>
        /// <typeparam name="TTo">Query result item type</typeparam>
        /// <param name="dbQuery">The dbQuery.</param>
        /// <param name="constraints">The constraints.</param>
        /// <param name="converter">Method used to convert the result </param>
        /// <returns>Search result</returns>
        public static IQueryResult <TTo> ToSearchResult <TFrom, TTo>(this DbQuery <TFrom> dbQuery, IQueryConstraints <TFrom> constraints, Func <TFrom, TTo> converter)
            where TFrom : class
            where TTo : class
        {
            if (dbQuery == null)
            {
                throw new ArgumentNullException(nameof(dbQuery));
            }

            if (constraints == null)
            {
                throw new ArgumentNullException(nameof(constraints));
            }

            int totalCount = constraints.Predicate == null
                                ? dbQuery.Count()
                                : dbQuery.Count(constraints.Predicate);

            IQueryable <TFrom> limitedQuery = constraints.ApplyTo(dbQuery);

            return(new QueryResult <TTo>(limitedQuery.Select(converter), totalCount));
        }
Example #6
0
        /// <summary>
        /// Execute LINQ query and fill a result.
        /// </summary>
        /// <typeparam name="TFrom">Database Model type</typeparam>
        /// <typeparam name="TTo">Query result item type</typeparam>
        /// <param name="dbQuery">The dbQuery.</param>
        /// <param name="constraints">The constraints.</param>
        /// <param name="converter">Method used to convert the result </param>
        /// <returns>Search result</returns>
        public static IQueryResult <TTo> ToSearchResult <TFrom, TTo>(this DbQuery <TFrom> dbQuery, IQueryConstraints <TFrom> constraints, Func <TFrom, TTo> converter)
            where TFrom : class
            where TTo : class
        {
            if (dbQuery == null)
            {
                throw new ArgumentNullException("dbQuery");
            }

            if (constraints == null)
            {
                throw new ArgumentNullException("constraints");
            }

            var totalCount = constraints.Predicate == null
                                ? dbQuery.Count()
                                : dbQuery.Count(constraints.Predicate);

            var limitedQuery = constraints.ApplyTo(dbQuery);

            return(new QueryResult <TTo>(limitedQuery.Select(converter), totalCount, constraints.PageNumber, constraints.PageSize));
        }