Ejemplo n.º 1
0
        static T Find <T>(ExpressionBuilder builder, BuildInfo buildInfo, Func <int, IBuildContext, T> action)
        {
            var expression = buildInfo.Expression;

            switch (expression.NodeType)
            {
            case ExpressionType.Constant:
            {
                var c = (ConstantExpression)expression;
                if (c.Value is IQueryable)
                {
                    return(action(1, null));
                }

                break;
            }

            case ExpressionType.Call:
            {
                var mc = (MethodCallExpression)expression;

                if (mc.Method.Name == "GetTable")
                {
                    if (expression.Type.IsGenericType && expression.Type.GetGenericTypeDefinition() == typeof(Table <>))
                    {
                        return(action(2, null));
                    }
                }

                break;
            }

            case ExpressionType.MemberAccess:

                if (expression.Type.IsGenericType && expression.Type.GetGenericTypeDefinition() == typeof(Table <>))
                {
                    return(action(3, null));
                }

                // Looking for association.
                //
                if (buildInfo.IsSubQuery && buildInfo.SqlQuery.From.Tables.Count == 0)
                {
                    var ctx = builder.GetContext(buildInfo.Parent, expression);
                    if (ctx != null)
                    {
                        return(action(4, ctx));
                    }
                }

                break;

            case ExpressionType.Parameter:
            {
                if (buildInfo.IsSubQuery && buildInfo.SqlQuery.From.Tables.Count == 0)
                {
                    var ctx = builder.GetContext(buildInfo.Parent, expression);
                    if (ctx != null)
                    {
                        return(action(4, ctx));
                    }
                }

                break;
            }
            }

            return(action(0, null));
        }