コード例 #1
0
ファイル: QExprGroup.cs プロジェクト: rahulchrty/badr-project
        public static QExprGroup Combine(QExprGroup subGroup1, QExprGroup subGroup2, string groupOperator = Constants.QUERY_AND)
        {
            QExprGroup group;
            if (groupOperator == Constants.QUERY_AND)
                group = new AndExprGroup();
            else
                group = new OrExprGroup();

            if (subGroup1 != null)
                group.SubGroups.Add(subGroup1);

            if (subGroup2 != null)
                group.SubGroups.Add(subGroup2);

            return group;
        }
コード例 #2
0
ファイル: Q.cs プロジェクト: rahulchrty/badr-project
        internal static QExprGroup CreateExprGroup(string groupOperator, CallInfo callInfo, object[] args)
        {
            if(callInfo != null
                && args != null
                && args.Length > 0
                && callInfo.ArgumentCount == args.Length)
            {
                int argsCount = args.Length;
                int namedArgsCount = callInfo.ArgumentNames.Count;

                QExpr[] qexprs = new QExpr[namedArgsCount];
                QExprGroup[] qgroups = new QExprGroup[argsCount - namedArgsCount];

                for (int i = 0; i < argsCount - namedArgsCount; i++)
                {
                    QExprGroup qgroup = args[i] as QExprGroup;
                    if (qgroup == null)
                        throw new Exception("An unnamed Q parameter must be of type QPredicate");

                    qgroups[i] = qgroup;
                }

                for (int i = 0; i < namedArgsCount; i++)
                {
                    string[] lhsAndOp = callInfo.ArgumentNames[i].Split(CUSTOM_QUERY_SYNTAX_SEP, StringSplitOptions.None);
                    if (lhsAndOp == null || lhsAndOp.Length == 0 || lhsAndOp.Length < 1)
                        throw new Exception("A Q parameter name must be composed of field name & operator name separated by '__' (double underscore)");

                    qexprs[i] = new QExpr(lhsAndOp[0],
                        lhsAndOp.Length >= 2 ? lhsAndOp[lhsAndOp.Length - 1] : Constants.QueryCompareOps.EXACT,
                        args[argsCount - namedArgsCount + i]);
                }

                QExprGroup exprGroup;

                if (groupOperator == Constants.QUERY_AND)
                    exprGroup = new AndExprGroup();
                else
                    exprGroup = new OrExprGroup();

                if (qgroups != null)
                    exprGroup.SubGroups.AddRange(qgroups);

                if (qexprs != null)
                    exprGroup.Expressions.AddRange(qexprs);

                return exprGroup;
            }

            return null;
        }
コード例 #3
0
ファイル: Manager.cs プロジェクト: rahulchrty/badr-project
        public Model Get(object pk = null)
        {
            if (pk != null)
            {
                QExprGroup qeg = new AndExprGroup().Add(
                    new QExpr(ModelInfo.ModelPKName, Constants.QueryCompareOps.EXACT, pk)
                );

                IEnumerable<Model> models = new Queryset(this).Filter(qeg).All();
                if (models != null && models.Count() == 1)
                    return models.Single();

                return null;
            }
            else
            {
                return OrmManager.CreateNewModel(ModelInfo.ModelApp, ModelInfo.ModelType);
            }
        }