protected virtual IQuery CreateQuery(
            string id, StorageProviderDefinition storageProviderDefinition, string statement, CommandParameter[] commandParameters, QueryType queryType)
        {
            ArgumentUtility.CheckNotNullOrEmpty("id", id);
            ArgumentUtility.CheckNotNull("storageProviderDefinition", storageProviderDefinition);
            ArgumentUtility.CheckNotNull("statement", statement);
            ArgumentUtility.CheckNotNull("commandParameters", commandParameters);

            var queryParameters = new QueryParameterCollection();

            foreach (var commandParameter in commandParameters)
            {
                queryParameters.Add(commandParameter.Name, commandParameter.Value, QueryParameterType.Value);
            }

            if (queryType == QueryType.Scalar)
            {
                return(QueryFactory.CreateScalarQuery(id, storageProviderDefinition, statement, queryParameters));
            }
            else if (queryType == QueryType.Collection)
            {
                return(QueryFactory.CreateCollectionQuery(id, storageProviderDefinition, statement, queryParameters, typeof(DomainObjectCollection)));
            }
            else
            {
                return(QueryFactory.CreateCustomQuery(id, storageProviderDefinition, statement, queryParameters));
            }
        }
Пример #2
0
        public void CreateScalarQuery()
        {
            var id                  = "id";
            var statement           = "stmt";
            var parameterCollection = new QueryParameterCollection();

            IQuery query = QueryFactory.CreateScalarQuery(id, TestDomainStorageProviderDefinition, statement, parameterCollection);

            Assert.That(query.CollectionType, Is.Null);
            Assert.That(query.ID, Is.EqualTo(id));
            Assert.That(query.Parameters, Is.SameAs(parameterCollection));
            Assert.That(query.QueryType, Is.EqualTo(QueryType.Scalar));
            Assert.That(query.Statement, Is.EqualTo(statement));
            Assert.That(query.StorageProviderDefinition, Is.SameAs(TestDomainStorageProviderDefinition));
        }