Пример #1
0
        public static T CaseWhen <T>(QueryCondition[] conditions, T[] thens, T @else)
            where T : IResult
        {
            if (conditions.Length != thens.Length)
            {
                throw new ArgumentException("The number of condition and then statement should match.");
            }

            ResultHelper <T> info           = ResultHelper.Of <T>();
            Type?            underlyingType = info.UnderlyingType;

            object[] arguments = new object[(conditions.Length << 1) + 1];
            int      argNum    = 0;

            for (int index = 0; index < conditions.Length; index++)
            {
                arguments[argNum] = conditions[index];
                argNum++;

                arguments[argNum] = WrapIfNull(thens[index]);
                argNum++;
            }
            arguments[argNum] = WrapIfNull(@else);

            return(info.NewFunctionResult(t => t.FnCaseWhenMultiple(conditions.Length), arguments, underlyingType));
        }
Пример #2
0
        public static T CaseWhen <T>(QueryCondition condition, Parameter @then, Parameter @else)
            where T : IPlainPrimitiveResult
        {
            ResultHelper <T> info           = ResultHelper.Of <T>();
            Type             underlyingType = info.UnderlyingType !;

            return(info.NewFunctionResult(t => t.FnCaseWhen, new object[] { condition, WrapIfNull(@then), WrapIfNull(@else) }, underlyingType));
        }
Пример #3
0
        //public QueryCondition All(Func<TResult, QueryCondition> condition)
        //{
        //    TResult alias = NewResult("item", new object[0]);
        //    QueryCondition test = condition.Invoke(alias);

        //    return new QueryCondition(new BooleanResult("all(item IN {base} WHERE {0})", new object[] { test }));
        //}
        //public QueryCondition Any(Func<TResult, QueryCondition> condition)
        //{
        //    TResult alias = NewResult("item", new object[0]);
        //    QueryCondition test = condition.Invoke(itemField);

        //    return new QueryCondition(new BooleanResult(itemField, "any(item IN {base} WHERE {0})", new object[] { test }));
        //}
        //public QueryCondition None(Func<TResult, QueryCondition> condition)
        //{
        //    TResult alias = NewResult("item", new object[0]);
        //    QueryCondition test = condition.Invoke(itemField);

        //    return new QueryCondition(new BooleanResult(this, "none(item IN {base} WHERE {0})", new object[] { test }));
        //}
        //public QueryCondition Single(Func<TResult, QueryCondition> condition)
        //{
        //    TResult alias = NewResult("item", new object[0]);
        //    QueryCondition test = condition.Invoke(itemField);

        //    return new QueryCondition(new BooleanResult(this, "single(item IN {base} WHERE {0})", new object[] { test }));
        //}

        public AsResult As(string aliasName, out TList alias)
        {
            AliasResult aliasResult = new AliasResult()
            {
                AliasName = aliasName
            };

            alias = ResultHelper.Of <TList>().NewAliasResult(aliasResult, null, null, null);
            return(this.As(aliasName));
        }
Пример #4
0
        public TList Sort(Func <TResult, string> fieldName, bool ascending)
        {
            string fld = fieldName.Invoke((TResult)this.Alias !);

            if (ascending)
            {
                return(ResultHelper.Of <TList>().NewAliasResult(this, t => t.FnListSortNode, new[] { new Literal(fld) }));
            }
            else
            {
                return(ResultHelper.Of <TList>().NewAliasResult(this, t => t.FnListSortNode, new[] { new Literal(string.Concat("^", fld)) }));
            }
        }
Пример #5
0
            internal FieldInfo(Transaction transaction, AsResult field)
            {
                Field      = field;
                FieldName  = field.GetFieldName() ?? throw new InvalidOperationException("GetFieldName() cannot be null here.");
                TargetType = field.GetResultType();
                ResultType = field.Result.GetType();
                Info       = ResultHelper.Of(ResultType);

                Conversion?converter = (TargetType is null) ? null : transaction.PersistenceProviderFactory.GetConverterFromStoredType(TargetType);

                ConvertMethod = (converter is null) ? null : (Func <object?, object?>)converter.Convert;

                Entity?    entity          = null;
                MethodInfo?getEntityMethod = ResultType.GetProperty("Entity")?.GetGetMethod();

                if (getEntityMethod is not null)
                {
                    entity = getEntityMethod.Invoke(field.Result, null) as Entity;
                }

                MethodInfo?method = (entity is null) ? null : entity !.RuntimeClassType !.GetMethod("Map", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, new Type[] { typeof(RawNode), typeof(string), typeof(Dictionary <string, object>), typeof(NodeMapping) }, null);

                MapMethod = (method is null) ? null : (Func <RawNode, string, Dictionary <string, object?>?, NodeMapping, OGM?>)Delegate.CreateDelegate(typeof(Func <RawNode, string, Dictionary <string, object?>?, NodeMapping, OGM?>), method, true);

                if (entity is null)
                {
                    return;
                }

                Type            listType       = typeof(List <>).MakeGenericType(entity.RuntimeReturnType);
                Type            jaggedListType = typeof(List <>).MakeGenericType(listType);
                ConstructorInfo listCtor       = listType.GetConstructor(new Type[] { typeof(int) });
                ConstructorInfo jaggedListCtor = jaggedListType.GetConstructor(new Type[] { typeof(int) });

                ParameterExpression capacity1 = Expression.Parameter(typeof(int), "capacity");
                ParameterExpression capacity2 = Expression.Parameter(typeof(int), "capacity");

                NewList       = Expression.Lambda <Func <int, IList> >(Expression.New(listCtor, capacity1), capacity1).Compile();
                NewJaggedList = Expression.Lambda <Func <int, IList> >(Expression.New(jaggedListCtor, capacity2), capacity2).Compile();
            }
Пример #6
0
 protected internal TList   NewList(Func <QueryTranslator, string?>?function, object[]?arguments   = null, Type?type = null) => ResultHelper.Of <TList>().NewAliasResult(this, function, arguments, type);