Example #1
0
        private static WhereSqlClauseBuilder GetWhereSqlClauseBuilderFromMapping(
            object condition,
            ConditionMappingItemCollection mapping,
            bool ignoreDefaultValue,
            AdjustConditionValueDelegate acv)
        {
            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            foreach (ConditionMappingItem item in mapping)
            {
                object data = GetValueFromObject(item, condition);

                if (data != null)
                {
                    if (ignoreDefaultValue == false || (ignoreDefaultValue == true && IsTypeDefaultValue(item, data) == false))
                    {
                        bool ignored = false;

                        data = AdjustValueBeforeAppendToBuilder(item, data);

                        if (acv != null)
                        {
                            data = acv(item.PropertyName, data, ref ignored);
                        }

                        if (ignored == false)
                        {
                            builder.AppendItem(item.DataFieldName, data, item.Operation, item.Template, item.IsExpression);
                        }
                    }
                }
            }

            return(builder);
        }
Example #2
0
        private static ConditionMappingItemCollection GetMappingItemsBySubClass(RelativeAttributes attrs, MemberInfo sourceMI)
        {
            ConditionMappingItemCollection items = new ConditionMappingItemCollection();

            System.Type subType = attrs.SubClassType != null ? attrs.SubClassType.Type : GetRealType(sourceMI);

            MemberInfo[] mis = GetTypeMembers(subType);

            foreach (SubConditionMappingAttribute attr in attrs.SubClassFieldMappings)
            {
                MemberInfo mi = GetMemberInfoByName(attr.SubPropertyName, mis);

                if (mi != null)
                {
                    ConditionMappingItem item = new ConditionMappingItem();

                    item.PropertyName         = sourceMI.Name;
                    item.SubClassPropertyName = attr.SubPropertyName;
                    item.MemberInfo           = mi;

                    if (attrs.SubClassType != null)
                    {
                        item.SubClassTypeDescription = attrs.SubClassType.TypeDescription;
                    }

                    FillMappingItemByAttr(item, attr);

                    items.Add(item);
                }
            }

            return(items);
        }
Example #3
0
 private static void MergeMappingItems(ConditionMappingItemCollection dest, ConditionMappingItemCollection src)
 {
     foreach (ConditionMappingItem item in src)
     {
         dest.Add(item);
     }
 }
Example #4
0
        /// <summary>
        /// 根据条件对象生成WhereSqlClauseBuilder
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="ignoreDefaultValue"></param>
        /// <param name="acv"></param>
        /// <returns></returns>
        public static WhereSqlClauseBuilder GetWhereSqlClauseBuilder(
            object condition,
            bool ignoreDefaultValue,
            AdjustConditionValueDelegate acv)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(condition != null, "condition");

            ConditionMappingItemCollection mapping = GetMappingInfo(condition.GetType());

            return(GetWhereSqlClauseBuilderFromMapping(condition, mapping, ignoreDefaultValue, acv));
        }
Example #5
0
        /// <summary>
        /// 得到组合的语句构造器。里面可能组合了Where和IN两种Builder
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="ignoreDefaultValue"></param>
        /// <param name="acv"></param>
        /// <param name="ignoreProperties">需要忽略的属性</param>
        /// <returns></returns>
        public static ConnectiveSqlClauseCollection GetConnectiveClauseBuilder(
            object condition,
            bool ignoreDefaultValue,
            AdjustConditionValueDelegate acv,
            params string[] ignoreProperties)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(condition != null, "condition");

            ConditionMappingItemCollection mapping = GetMappingInfo(condition.GetType());

            return(GetConnectiveSqlClauseBuilderFromMapping(condition, mapping, ignoreDefaultValue, acv, ignoreProperties));
        }
Example #6
0
        /// <summary>
        /// 得到某个类型的条件表达式映射方式
        /// </summary>
        /// <param name="type">类型信息</param>
        /// <returns>映射方式</returns>
        public static ConditionMappingItemCollection GetMappingInfo(System.Type type)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(type != null, "type");

            ConditionMappingItemCollection result = null;

            if (ConditionMappingCache.Instance.TryGetValue(type, out result) == false)
            {
                result = GetMappingItemCollection(type);
                ConditionMappingCache.Instance[type] = result;
            }

            return(result);
        }
Example #7
0
        private static ConnectiveSqlClauseCollection GetConnectiveSqlClauseBuilderFromMapping(
            object condition,
            ConditionMappingItemCollection mapping,
            bool ignoreDefaultValue,
            AdjustConditionValueDelegate acv,
            string[] ignoreProperties)
        {
            ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection();

            WhereSqlClauseBuilder whereBuilder = GetWhereSqlClauseBuilderFromMapping(condition, mapping.FilterByType <ConditionMappingItem>(), ignoreDefaultValue, acv, ignoreProperties);

            connectiveBuilder.Add(whereBuilder);

            FillInSqlClauseBuilderFromMapping(connectiveBuilder, condition, mapping.FilterByType <InConditionMappingItem>(), ignoreDefaultValue, acv, ignoreProperties);

            return(connectiveBuilder);
        }
Example #8
0
        private static ConditionMappingItemCollection GetMappingItemCollection(System.Type type)
        {
            ConditionMappingItemCollection result = new ConditionMappingItemCollection();

            MemberInfo[] mis = GetTypeMembers(type);

            foreach (MemberInfo mi in mis)
            {
                if (mi.MemberType == MemberTypes.Field || mi.MemberType == MemberTypes.Property)
                {
                    ConditionMappingItemCollection items = CreateMappingItems(mi);

                    MergeMappingItems(result, items);
                }
            }

            return(result);
        }
Example #9
0
        private static ConditionMappingItemCollection GetMappingItems(RelativeAttributes attrs, MemberInfo mi)
        {
            ConditionMappingItemCollection items = new ConditionMappingItemCollection();

            ConditionMappingItem item = new ConditionMappingItem();

            item.PropertyName  = mi.Name;
            item.DataFieldName = mi.Name;

            if (attrs.FieldMapping != null)
            {
                FillMappingItemByAttr(item, attrs.FieldMapping);
            }

            item.MemberInfo = mi;

            items.Add(item);

            return(items);
        }
Example #10
0
        private static ConditionMappingItemCollection CreateMappingItems(MemberInfo mi)
        {
            ConditionMappingItemCollection result = null;
            bool isDoMapping = false;

            RelativeAttributes attrs = null;

            //if (mi.Name != "Item" && GetRealType(mi).GetInterface("ICollection") == null)
            if (mi.Name != "Item")
            {
                attrs = GetRelativeAttributes(mi);

                if (attrs.NoMapping == null)
                {
                    isDoMapping = true;
                }
            }

            if (isDoMapping == true)
            {
                if (attrs != null)
                {
                    if (attrs.SubClassFieldMappings.Count > 0)
                    {
                        result = GetMappingItemsBySubClass(attrs, mi);
                    }
                    else
                    {
                        result = GetMappingItems(attrs, mi);
                    }
                }
            }
            else
            {
                result = new ConditionMappingItemCollection();
            }

            return(result);
        }
Example #11
0
        private static ConditionMappingItem FindItemBySubClassPropertyName(string subPropertyName, ConditionMappingItemCollection items)
        {
            ConditionMappingItem result = null;

            foreach (ConditionMappingItem item in items)
            {
                if (item.SubClassPropertyName == subPropertyName)
                {
                    result = item;
                    break;
                }
            }

            return(result);
        }