Esempio n. 1
0
        /// <summary>
        /// Generate a Search Builder instance based on the supplied information.
        /// </summary>
        /// <param name="entityTypeRepository">List of entity definitions known to the system.</param>
        /// <param name="search">Search instance to build.</param>
        /// <param name="searchParser">Output parameter to return the initialized Search Parser.</param>
        /// <param name="parameterize">When true, will parameterize the search, otherwise will not.</param>
        /// <returns>Search Builder instance run against supplied Search.</returns>
        public static IDSSearchBuilder CreateSearchBuilder(IDSEntityTypeRepository entityTypeRepository, DSSearch search, out DSSearchParser searchParser, bool parameterize = false)
        {
            var queryBuilder = new DSSQLSearchBuilder(parameterize);

            searchParser = new DSSearchParser(entityTypeRepository, queryBuilder);
            searchParser.BuildSearch(search);

            return(queryBuilder);
        }
        /// <summary>
        /// Initialize a proper search builder for the supplied filter.
        /// </summary>
        /// <param name="testWhere">The filter to generate a search builder for.</param>
        /// <returns>Search builder for the supplied filter</returns>
        private DSSQLFilterBuilder GetBuilder(DSPredicate testWhere)
        {
            var sqlBuilder   = new DSSQLSearchBuilder();
            var searchParser = new DSSearchParser(_entityTypeRepository, sqlBuilder);
            var search       = new DSSearch(TestObjectC.ClassName);

            search.Where = testWhere;

            searchParser.BuildSearch(search);

            return((DSSQLFilterBuilder)sqlBuilder.WhereBuilder);
        }
Esempio n. 3
0
        /// <summary>
        /// Executes a supplied DSSearch against a SQL Server database.
        /// </summary>
        /// <param name="search">The Search to execute.</param>
        /// <param name="ctx">The current data context.</param>
        /// <returns>Results from the search or any erorr messages generated.</returns>
        public DSSearchResponse ExecuteSearch(DSSearch search, DSDataContext ctx)
        {
            var queryBuilder = new DSSQLSearchBuilder(); // TODO - should this be injected? possible to use different one with different Filter Builder for ex.
            var searchParser = new DSSearchParser(_entityTypeRepository, queryBuilder);

            searchParser.BuildSearch(search);

            // TODO - Implement the Parameterize capability
            var sql = queryBuilder.ToString();

            var connString = ctx.GetConnectionString();
            var results    = new DataTable();

            using (var da = new SqlDataAdapter(sql, connString))
            {
                da.Fill(results);
            }

            int totalRecords = results.Rows.Count;

            if (totalRecords == search.PageSize)
            {
                // We need to see if there are more than just this page
                var countResults = new DataTable();
                using (var da = new SqlDataAdapter(queryBuilder.ToStringForCount(), connString))
                {
                    da.Fill(countResults);
                }

                totalRecords = (int)countResults.Rows[0][0];
            }
            else
            {
                totalRecords += (search.Page - 1) * search.PageSize;
            }

            return(new DSSearchResponse
            {
                Errors = null,
                TotalRecords = totalRecords,
                Results = results.ToEntityList <DSEntity>()
            });
        }