예제 #1
0
        protected virtual Expression VisitDeclaration(DbDeclarationCommand decl)
        {
            var variables = this.VisitVariableDeclarations(decl.Variables);
            var source    = this.Visit(decl.Source) as DbSelectExpression;

            return(this.UpdateDeclaration(decl, variables, source));
        }
예제 #2
0
        protected override Expression VisitDeclaration(DbDeclarationCommand decl)
        {
            if (decl.Source != null)
            {
                var projection = new DbProjectionExpression
                                 (
                    decl.Source,
                    Expression.NewArrayInit(typeof(object), decl.Variables.Select(v => v.Expression.Type.GetTypeInfo().IsValueType ? Expression.Convert(v.Expression, typeof(object)) : v.Expression).ToArray()),
                    DbAggregator.GetAggregator(typeof(object[]), typeof(IEnumerable <object[]>))
                                 );

                var vars = Expression.Parameter(typeof(object[]), "vars");

                this.variables.Add(vars);
                this.initializers.Add(Expression.Constant(null, typeof(object[])));

                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    var v  = decl.Variables[i];
                    var nv = new DbNamedValueExpression
                             (
                        v.Name, v.QueryType,
                        Expression.Convert(Expression.ArrayIndex(vars, Expression.Constant(i)), v.Expression.Type)
                             );

                    this.variableMap.Add(v.Name, nv);
                }

                return(MakeAssign(vars, this.Visit(projection)));
            }

            throw new InvalidOperationException("Declaration query not allowed for this langauge");
        }
예제 #3
0
        protected DbDeclarationCommand UpdateDeclaration(DbDeclarationCommand decl, IEnumerable <DbVariableDeclaration> variables, DbSelectExpression source)
        {
            if (variables != decl.Variables || source != decl.Source)
            {
                return(new DbDeclarationCommand(variables, source));
            }

            return(decl);
        }
예제 #4
0
        private DbCommandExpression GetDependentGeneratedVariableDeclaration(MappingEntity entity, MappingTable table, List <MemberInfo> members, Expression instance, Dictionary <MemberInfo, Expression> map)
        {
            var genIdCommand = null as DbDeclarationCommand;
            var generatedIds = this.mapping.GetMappedMembers(entity).Where(m => this.mapping.IsPrimaryKey(entity, m) && this.mapping.IsGenerated(entity, m)).ToList();

            if (generatedIds.Count > 0)
            {
                genIdCommand = this.GetGeneratedIdCommand(entity, members, map);

                if (members.Count == generatedIds.Count)
                {
                    return(genIdCommand);
                }
            }

            members = members.Except(generatedIds).ToList();

            var tableAlias = new TableAlias();
            var tex        = new DbTableExpression(tableAlias, entity, this.mapping.GetTableName(table));

            var where = null as Expression;

            if (generatedIds.Count > 0)
            {
                where = generatedIds.Select((m, i) => this.GetMemberExpression(tex, entity, m).Equal(map[m])).Aggregate((x, y) => x.And(y));
            }
            else
            {
                where = this.GetIdentityCheck(tex, entity, instance);
            }

            var selectAlias = new TableAlias();
            var columns     = new List <DbColumnDeclaration>();
            var variables   = new List <DbVariableDeclaration>();

            foreach (var mi in members)
            {
                var col = (DbColumnExpression)this.GetMemberExpression(tex, entity, mi);

                columns.Add(new DbColumnDeclaration(this.mapping.GetColumnName(entity, mi), col, col.QueryType));

                var vcol = new DbColumnExpression(col.Type, col.QueryType, selectAlias, col.Name);

                variables.Add(new DbVariableDeclaration(mi.Name, col.QueryType, vcol));
                map.Add(mi, new DbVariableExpression(mi.Name, col.Type, col.QueryType));
            }

            var genMembersCommand = new DbDeclarationCommand(variables, new DbSelectExpression(selectAlias, columns, tex, where));

            if (genIdCommand != null)
            {
                return(new DbBlockCommand(genIdCommand, genMembersCommand));
            }

            return(genMembersCommand);
        }
예제 #5
0
 protected override Expression VisitDeclaration(DbDeclarationCommand decl)
 {
     throw new NotSupportedException();
 }