Exemplo n.º 1
0
        private ConditionBuilder GetBuilder(Expression <Func <M, bool> > expression)
        {
            ConditionBuilder conditionBuilder = new ConditionBuilder();

            if (expression == null)
            {
                conditionBuilder.Condition = string.Empty;
            }
            else
            {
                conditionBuilder.Build(expression.Body, this.type, false);
            }
            return(conditionBuilder);
        }
Exemplo n.º 2
0
        private object ProviderCallBack(Expression expression, Type returnType)
        {
            MethodCallExpression methodCallExpression = (MethodCallExpression)expression;
            ConditionBuilder     conditionBuilder     = new ConditionBuilder();

            conditionBuilder.Build(expression, this.type, true);
            object obj = null;
            string name;

            if ((name = methodCallExpression.Method.Name) != null)
            {
                if (_sqlKeywords == null)
                {
                    _sqlKeywords = new Dictionary <string, int>(8)
                    {
                        {
                            "FirstOrDefault",
                            0
                        },

                        {
                            "First",
                            1
                        },

                        {
                            "Select",
                            2
                        },

                        {
                            "Skip",
                            3
                        },

                        {
                            "Take",
                            4
                        },

                        {
                            "OrderByDescending",
                            5
                        },

                        {
                            "OrderBy",
                            6
                        },

                        {
                            "Count",
                            7
                        }
                    };
                }
                int num;
                if (_sqlKeywords.TryGetValue(name, out num))
                {
                    DataTable dataTable;
                    switch (num)
                    {
                    case 0:
                    case 1:
                    {
                        dataTable = this.DBbase.GetDataTable(conditionBuilder.Condition, conditionBuilder.Arguments.ToArray());
                        object obj2;
                        if (AnonymouseHelper.IsAnonyousType(returnType))
                        {
                            obj2 = ConvertHelper.GetAnonymous(dataTable, returnType);
                        }
                        else
                        {
                            obj2 = ConvertHelper.GetList(dataTable, returnType);
                        }
                        IEnumerable enumerable = (IEnumerable)obj2;
                        IEnumerator enumerator = enumerable.GetEnumerator();
                        try
                        {
                            if (enumerator.MoveNext())
                            {
                                object current = enumerator.Current;
                                obj = current;
                            }
                            return(obj);
                        }
                        finally
                        {
                            IDisposable disposable = enumerator as IDisposable;
                            if (disposable != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        break;
                    }

                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                        break;

                    case 7:
                        obj = this.DBbase.GetSingle(conditionBuilder.Condition, conditionBuilder.Arguments.ToArray());
                        obj = Convert.ToInt32(obj);
                        return(obj);

                    default:
                        return(obj);
                    }
                    Type[] genericArguments = returnType.GetGenericArguments();
                    returnType = ((genericArguments.Length == 0) ? this.type : genericArguments[0]);
                    dataTable  = this.DBbase.GetDataTable(conditionBuilder.Condition, conditionBuilder.Arguments.ToArray());
                    if (AnonymouseHelper.IsAnonyousType(returnType))
                    {
                        obj = ConvertHelper.GetAnonymous(dataTable, returnType);
                    }
                    else
                    {
                        obj = ConvertHelper.GetList(dataTable, returnType);
                    }
                    obj = (IEnumerable)obj;
                }
            }
            return(obj);
        }