コード例 #1
0
        /// <summary>
        /// Creates a new query object, loading its data from the <see cref="QueryConfiguration"/>.
        /// </summary>
        /// <param name="id">The id of the query to load.</param>
        /// <param name="queryParameterCollection">The parameter collection to use for the query.</param>
        /// <returns>An implementation of <see cref="IQuery"/> corresponding to the <see cref="QueryDefinition"/> with the given <paramref name="id"/>
        /// held by the current <see cref="QueryConfiguration"/>.</returns>
        public static IQuery CreateQueryFromConfiguration(string id, QueryParameterCollection queryParameterCollection)
        {
            ArgumentUtility.CheckNotNullOrEmpty("id", id);
            var queryDefinition = DomainObjectsConfiguration.Current.Query.QueryDefinitions.GetMandatory(id);

            return(new Query(queryDefinition, queryParameterCollection));
        }
コード例 #2
0
        /// <summary>
        /// Creates a new query object from a given <paramref name="queryDefinition"/>.
        /// </summary>
        /// <param name="queryDefinition">The query definition to construct a query from.</param>
        /// <param name="queryParameterCollection">The parameter collection to use for the query.</param>
        /// <returns>An implementation of <see cref="IQuery"/> corresponding to <paramref name="queryDefinition"/>.</returns>
        public static IQuery CreateQuery(QueryDefinition queryDefinition, QueryParameterCollection queryParameterCollection)
        {
            ArgumentUtility.CheckNotNull("queryDefinition", queryDefinition);
            ArgumentUtility.CheckNotNull("queryParameterCollection", queryParameterCollection);

            return(new Query(queryDefinition, queryParameterCollection));
        }
コード例 #3
0
        // construction and disposing

        /// <summary>
        /// Initializes a new instance of the <see cref="Query"/> class using a <see cref="Configuration.QueryDefinition"/> and a given collection of <see cref="QueryParameter"/>s.
        /// </summary>
        /// <param name="definition">The <see cref="Configuration.QueryDefinition"/> to use for the query.</param>
        /// <param name="parameters">The <see cref="QueryParameter"/>s to use for executing the query.</param>
        /// <exception cref="System.ArgumentNullException">
        ///   <paramref name="definition"/> is <see langword="null"/>.<br /> -or- <br />
        ///   <paramref name="parameters"/> is <see langword="null"/>.
        /// </exception>
        public Query(QueryDefinition definition, QueryParameterCollection parameters)
        {
            ArgumentUtility.CheckNotNull("definition", definition);
            ArgumentUtility.CheckNotNull("parameters", parameters);

            _definition = definition;
            _parameters = parameters;
        }
コード例 #4
0
        /// <summary>
        /// Creates a new custom collection query with the given statement, parameters, and metadata.
        /// Note that creating queries with a hard-coded SQL statement is not very flexible and not portable at all.
        /// Therefore, the <see cref="CreateLinqQuery{T}()"/> and <see cref="CreateQueryFromConfiguration(string)"/>
        /// methods should usually be preferred to this method.
        /// </summary>
        /// <param name="id">A string identifying the query.</param>
        /// <param name="storageProviderDefinition">The <see cref="StorageProviderDefinition"/> of the storage provider used to execute the query.</param>
        /// <param name="statement">The custom query statement.</param>
        /// <param name="queryParameterCollection">The parameter collection to be used for the query.</param>
        /// <returns>An implementation of <see cref="IQuery"/> with the given statement, parameters, and metadata.</returns>
        public static IQuery CreateCustomQuery(
            string id,
            StorageProviderDefinition storageProviderDefinition,
            string statement,
            QueryParameterCollection queryParameterCollection)
        {
            var definition = new QueryDefinition(id, storageProviderDefinition, statement, QueryType.Custom, null);

            return(new Query(definition, queryParameterCollection));
        }
コード例 #5
0
        // standard constructor for collections
        /// <summary>
        /// Initializes a new <b>QueryParameterCollection</b> as a shallow copy of a given <see cref="QueryParameterCollection"/>.
        /// </summary>
        /// <remarks>
        /// The new <b>QueryParameterCollection</b> has the same items as the given <paramref name="collection"/>.
        /// </remarks>
        /// <param name="collection">The <see cref="QueryParameterCollection"/> to copy. Must not be <see langword="null"/>.</param>
        /// <param name="makeCollectionReadOnly">Indicates whether the new collection should be read-only.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="collection"/> is <see langword="null"/>.</exception>
        public QueryParameterCollection(QueryParameterCollection collection, bool makeCollectionReadOnly)
        {
            ArgumentUtility.CheckNotNull("collection", collection);

            foreach (QueryParameter parameter in collection)
            {
                Add(parameter);
            }

            this.SetIsReadOnly(makeCollectionReadOnly);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new collection query with the given statement, parameters, and metadata.
        /// Note that creating queries with a hard-coded SQL statement is not very flexible and not portable at all.
        /// Therefore, the <see cref="CreateLinqQuery{T}()"/> and <see cref="CreateQueryFromConfiguration(string)"/>
        /// methods should usually be preferred to this method.
        /// </summary>
        /// <param name="id">A string identifying the query.</param>
        /// <param name="storageProviderDefinition">The <see cref="StorageProviderDefinition"/> of the storage provider used to execute the query.</param>
        /// <param name="statement">The collection query statement.</param>
        /// <param name="queryParameterCollection">The parameter collection to be used for the query.</param>
        /// <param name="collectionType">The collection type to be returned from the query. Pass <see cref="DomainObjectCollection"/> if you don't care
        /// about the collection type. The type passed here is used by <see cref="QueryResult{T}.ToCustomCollection"/>.</param>
        /// <returns>An implementation of <see cref="IQuery"/> with the given statement, parameters, and metadata.</returns>
        public static IQuery CreateCollectionQuery(
            string id,
            StorageProviderDefinition storageProviderDefinition,
            string statement,
            QueryParameterCollection queryParameterCollection,
            Type collectionType)
        {
            ArgumentUtility.CheckNotNull("id", id);
            ArgumentUtility.CheckNotNull("storageProviderDefinition", storageProviderDefinition);
            ArgumentUtility.CheckNotNull("statement", statement);
            ArgumentUtility.CheckNotNull("queryParameterCollection", queryParameterCollection);
            ArgumentUtility.CheckNotNull("collectionType", collectionType);

            var definition = new QueryDefinition(id, storageProviderDefinition, statement, QueryType.Collection, collectionType);

            return(new Query(definition, queryParameterCollection));
        }
コード例 #7
0
        private static QueryParameterCollection CopyQueryParameters(this IQuery template, Dictionary <object, object> parameterValues)
        {
            if (template.Parameters.Count != parameterValues.Count)
            {
                throw new InvalidOperationException(
                          String.Format(
                              "Number of supplied query parameters ({0}) does not match the number of parameters in the template query ({1}) .",
                              template.Parameters.Count,
                              parameterValues.Count));
            }

            var queryParameters = new QueryParameterCollection();

            foreach (QueryParameter templateParameter in template.Parameters)
            {
                queryParameters.Add(templateParameter.CopyQueryParameter(parameterValues));
            }

            return(queryParameters);
        }