Example #1
0
        protected virtual StatementPart VisitColumnMemberAccess(MemberExpression memberExpression)
        {
            if (memberExpression.Member.DeclaringType == typeof(string) &&
                memberExpression.Member.Name == "Length")
            {
                return(new StatementPart(
                           DialectProvider.GetStringFunction("length",
                                                             _statement,
                                                             null,
                                                             null)));
            }

            if (memberExpression.Member.DeclaringType == typeof(DateTime))
            {
                switch (memberExpression.Member.Name)
                {
                case "Year":
                case "Month":
                case "Day":
                case "Hour":
                case "Minute":
                case "Second":
                    return(new StatementPart(
                               DialectProvider.GetDatePartFunction(memberExpression.Member.Name, _statement)));

                default:
                    throw new NotSupportedException();
                }
            }

            return(null);
        }
Example #2
0
        protected virtual StatementPart VisitColumnMethodCall(MethodCallExpression methodCallExpression)
        {
            var args = new List <StatementPart>();

            if (methodCallExpression.Arguments.Count == 1 &&
                methodCallExpression.Arguments[0].NodeType == ExpressionType.Constant)
            {
                args.Add(VisitConstant((ConstantExpression)methodCallExpression.Arguments[0]));
            }
            else
            {
                args.AddRange(VisitExpressionList(methodCallExpression.Arguments));
            }

            var quotedColName = Visit(methodCallExpression.Object).ToString();

            var statement = DialectProvider.GetStringFunction(
                methodCallExpression.Method.Name,
                quotedColName,
                Parameters,
                args.Select(x => x.Text).ToArray());

            return(new StatementPart(statement));
        }
Example #3
0
        protected override StatementPart VisitMemberAccess(MemberExpression m)
        {
            //Nullable support HasValue
            if (m.Member.DeclaringType != null &&
                Nullable.GetUnderlyingType(m.Member.DeclaringType) != null &&
                m.Member.Name == "HasValue")
            {
                return(new StatementPart(Visit(m.Expression) + " IS NOT NULL"));
            }

            if (m.Member.DeclaringType == typeof(string) &&
                m.Member.Name == "Length")
            {
                return(new StatementPart(
                           DialectProvider.GetStringFunction("length",
                                                             Visit(m.Expression).ToString(),
                                                             null,
                                                             null)));
            }

            if (m.Member.DeclaringType == typeof(DateTime) || m.Member.DeclaringType == typeof(DateTime?))
            {
                return(VisitDateTimeMemberAccess(m));
            }

            if (m.Expression != null && (m.Expression.NodeType == ExpressionType.Parameter ||
                                         m.Expression.NodeType == ExpressionType.Convert))
            {
                var propertyInfo = m.Member as PropertyInfo;
                return(new ColumnAccessPart(GetQuotedColumnName(m.Member.Name), propertyInfo.PropertyType));
            }

            var r = Expression.Lambda(m).Compile().DynamicInvoke();

            return(r != null?AddParameter(r) : null);
        }