Beispiel #1
0
 /// <summary>
 /// Handle parameter query object before use
 /// </summary>
 /// <param name="parameterQuery">Parameter query</param>
 /// <param name="parameterQueryOption">Parameter query option</param>
 /// <returns>Return the newest query object</returns>
 internal static TQuery HandleParameterQueryBeforeUse <TQuery>(TQuery parameterQuery, QueryParameterOptions parameterQueryOption) where TQuery : IQuery
 {
     if (parameterQuery == null)
     {
         return(parameterQuery);
     }
     if (EnableCopyParameterQueryObject)
     {
         parameterQuery = (TQuery)parameterQuery.Clone();
     }
     if (parameterQueryOption != null)
     {
         if (!string.IsNullOrWhiteSpace(parameterQueryOption.QueryFieldName))
         {
             parameterQuery.ClearQueryFields();
             parameterQuery.AddQueryFields(parameterQueryOption.QueryFieldName);
         }
     }
     return(parameterQuery);
 }
Beispiel #2
0
        /// <summary>
        /// Add queryInfo query item handler
        /// </summary>
        /// <param name="originalQuery">Original query</param>
        /// <param name="queryItem">Parameter query item</param>
        /// <param name="parameterQueryOption">Parameter query option</param>
        static IQueryItem AddQueryInfoQueryItemHandler(DefaultQuery originalQuery, IQueryItem queryItem, QueryParameterOptions parameterQueryOption)
        {
            if (originalQuery == null || queryItem == null)
            {
                return(null);
            }
            DefaultQuery valueQuery = queryItem as DefaultQuery;

            valueQuery = HandleParameterQueryBeforeUse(valueQuery, parameterQueryOption);
            valueQuery.SetEntityType(originalQuery.entityType);
            originalQuery.SetHasSubQuery(originalQuery.HasSubquery || valueQuery.HasSubquery);
            originalQuery.SetHasJoin(originalQuery.HasJoin || valueQuery.HasJoin);
            originalQuery.SetHasRecurveCriteria(originalQuery.HasRecurveCriteria || valueQuery.HasRecurveCriteria);
            originalQuery.equalCriteriaCollection.AddRange(valueQuery.equalCriteriaCollection);
            originalQuery.atomicConditionCount += valueQuery.AtomicConditionCount;
            originalQuery.allConditionFieldNameCollection.AddRange(valueQuery.AllConditionFieldNames);
            originalQuery.alreadySetGlobalCondition |= valueQuery.alreadySetGlobalCondition;
            originalQuery.SetHasConverter(originalQuery.HasConverter || valueQuery.HasConverter);
            return(valueQuery);
        }
Beispiel #3
0
        /// <summary>
        /// Add a IQueryItem
        /// </summary>
        /// <param name="queryOperator">Connect operator</param>
        /// <param name="queryItem">query item</param>
        /// <param name="queryOption">query parameter option</param>
        public IQuery AddQueryItem(QueryOperator queryOperator, IQueryItem queryItem, QueryParameterOptions queryOption = null)
        {
            #region invoke handler

            var queryItemTypeId = queryItem?.GetType().GUID ?? Guid.Empty;
            Func <DefaultQuery, IQueryItem, QueryParameterOptions, IQueryItem> handler = null;
            QueryManager.AddQueryItemHandlers?.TryGetValue(queryItemTypeId, out handler);
            if (handler != null)
            {
                queryItem = handler(this, queryItem, queryOption);
            }

            #endregion

            if (queryItem != null)
            {
                //clear data
                queryExpressionCaches?.Clear();
                criteriaCollection.Add(new Tuple <QueryOperator, IQueryItem>(queryOperator, queryItem));
            }
            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// Add criteria query item handler
        /// </summary>
        /// <param name="originalQuery">Original query</param>
        /// <param name="queryItem">Parameter query item</param>
        /// <param name="parameterQueryOption">Parameter query option</param>
        static IQueryItem AddCriteriaQueryItemHandler(DefaultQuery originalQuery, IQueryItem queryItem, QueryParameterOptions parameterQueryOption)
        {
            if (originalQuery == null || queryItem == null)
            {
                return(null);
            }
            Criteria criteria   = queryItem as Criteria;
            var      queryValue = criteria.Value as IQuery;

            originalQuery.SetHasConverter(originalQuery.HasConverter || criteria.Converter != null);
            if (queryValue != null)
            {
                if (queryValue.GetEntityType() == null)
                {
                    throw new EZNEWException("the IQuery object used for the subquery must set the property EntityType");
                }
                queryValue = HandleParameterQueryBeforeUse(queryValue, parameterQueryOption);
                criteria.SetValue(queryValue);
                originalQuery.subqueryCollection.Add(queryValue);
                originalQuery.SetHasSubQuery(true);
                originalQuery.SetHasJoin(originalQuery.HasJoin || queryValue.HasJoin);
                originalQuery.SetHasRecurveCriteria(originalQuery.HasRecurveCriteria || queryValue.HasRecurveCriteria);
                originalQuery.SetHasConverter(originalQuery.HasConverter || queryValue.HasConverter);
            }
            else
            {
                bool             equalCriterial          = false;
                bool             verifyValueNull         = false;
                CriteriaOperator verifyValueNullOperator = CriteriaOperator.IsNull;
                switch (criteria.Operator)
                {
                case CriteriaOperator.Equal:
                    equalCriterial  = true;
                    verifyValueNull = true;
                    break;

                case CriteriaOperator.NotEqual:
                    verifyValueNull         = true;
                    verifyValueNullOperator = CriteriaOperator.NotNull;
                    break;

                case CriteriaOperator.In:
                    equalCriterial = true;
                    break;
                }
                if (criteria.GetCriteriaRealValue() == null && verifyValueNull)
                {
                    equalCriterial    = false;
                    criteria.Operator = verifyValueNullOperator;
                }
                if (equalCriterial)
                {
                    originalQuery.equalCriteriaCollection.Add(criteria);
                }
            }
            originalQuery.atomicConditionCount++;
            originalQuery.allConditionFieldNameCollection.Add(criteria.Name);
            return(criteria);
        }
Beispiel #5
0
        /// <summary>
        /// Add a criteria
        /// </summary>
        /// <param name="queryOperator">Connect operator</param>
        /// <param name="fieldName">Field name</param>
        /// <param name="criteriaOperator">Condition operator</param>
        /// <param name="value">Value</param>
        /// <param name="converter">Converter</param>
        /// <param name="queryOption">query parameter option</param>
        public IQuery AddCriteria(QueryOperator queryOperator, string fieldName, CriteriaOperator criteriaOperator, dynamic value, ICriteriaConverter converter = null, QueryParameterOptions queryOption = null)
        {
            if (string.IsNullOrWhiteSpace(fieldName))
            {
                return(this);
            }
            Criteria newCriteria = Criteria.CreateNewCriteria(fieldName, criteriaOperator, value);

            newCriteria.Converter = converter;
            return(AddQueryItem(queryOperator, newCriteria, queryOption));
        }