Ejemplo n.º 1
0
        protected override Expression VisitMember(MemberExpression node)
        {
            // ----------------------------------------------------
            // original:
            //  dbParam.DatabaseTable
            // ----------------------------------------------------
            // transformed:
            //  executionContextParam.Database.Tables.FindTable<T>
            // ----------------------------------------------------

            if (typeof(IDatabase).IsAssignableFrom(node.Member.DeclaringType) &&
                node.Expression is ParameterExpression)
            {
                Type entityType = DatabaseReflectionHelper.GetTableEntityType(node.Type);

                // Check if ITable<>
                if (entityType != null)
                {
                    Expression database =
                        Expression.Property(
                            this.context.Parameter,
                            DatabaseMembers.ExecutionContext_Database);

                    Expression tables =
                        Expression.Property(
                            database,
                            DatabaseMembers.Database_Tables);

                    return(Expression.Call(DatabaseMembers.TableCollectionExtensions_FindTable.MakeGenericMethod(entityType), tables));
                }
            }

            return(base.VisitMember(node));
        }
Ejemplo n.º 2
0
        protected override Expression VisitMember(MemberExpression node)
        {
            Type type = ReflectionHelper.GetMemberType(node.Member);

            if (typeof(ITable).IsAssignableFrom(type))
            {
                Type entityType = DatabaseReflectionHelper.GetTableEntityType(node.Type);

                // Check if ITable<>
                if (entityType != null)
                {
                    this.entityTypes.Add(entityType);
                }
            }

            return(base.VisitMember(node));
        }
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            // ----------------------------------------------------
            // original:
            //  executionContext.Database.Tables.FindTable<>   OR
            //  dbConst.Tables.FindTable<>                     OR
            //  const.db.Tables.FindTable<>
            // ----------------------------------------------------
            // transformed:
            //  tableConstant
            // ----------------------------------------------------

            if (!node.Method.IsGenericMethod ||
                node.Method.GetGenericMethodDefinition() != DatabaseMembers.TableCollectionExtensions_FindTable)
            {
                return(base.VisitMethodCall(node));
            }

            Type entityType = DatabaseReflectionHelper.GetTableEntityType(node.Type);

            if (entityType == null)
            {
                // TODO: This should not happen, log this
                return(base.VisitMethodCall(node));
            }

            MemberExpression tablesProp = node.Arguments[0] as MemberExpression;

            if (tablesProp == null || tablesProp.Member != DatabaseMembers.Database_Tables)
            {
                return(base.VisitMethodCall(node));
            }

            IDatabase database = this.FindDatabase(tablesProp.Expression);

            if (database == null)
            {
                // TODO: This should not happen, log this
                return(base.VisitMethodCall(node));
            }

            ITable table = database.Tables.FindTable(entityType);

            return(Expression.Constant(table));
        }
Ejemplo n.º 4
0
        protected override Expression VisitConstant(ConstantExpression node)
        {
            //// ----------------------------------------------
            //// original:
            ////  DatabaseTable
            //// ----------------------------------------------
            //// transformed:
            ////  DatabaseTable.SelectAll<>
            //// ----------------------------------------------

            Type entityType = DatabaseReflectionHelper.GetTableEntityType(node.Type);

            if (entityType != null)
            {
                return(CreateSelectTableExpression(node, entityType));
            }

            return(base.VisitConstant(node));
        }
Ejemplo n.º 5
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            //// ----------------------------------------------
            //// original:
            ////  dbParam.FindTable<>
            //// ----------------------------------------------
            //// transformed:
            ////  dbParam.FindTable<>.SelectAll<>
            //// ----------------------------------------------

            Type entityType = DatabaseReflectionHelper.GetTableEntityType(node.Type);

            if (entityType != null &&
                node.Method.IsGenericMethod &&
                node.Method.GetGenericMethodDefinition() == DatabaseMembers.TableCollectionExtensions_FindTable)
            {
                return(CreateSelectTableExpression(node, entityType));
            }

            return(base.VisitMethodCall(node));
        }