Exemplo n.º 1
0
 protected virtual InsertCommandExpression UpdateInsert(OInsertCommandExpression insert, IdentifiableExpression table,
     IEnumerable<FieldAssignment> assignments, ProjectionExpression projection)
 {
     if (table != insert.Identifiable || assignments != insert.Assignments || projection.Projector != insert.Projection.Projector)
     {
         return new OInsertCommandExpression(table, assignments, projection.Projector);
     }
     return insert;
 }
Exemplo n.º 2
0
        protected virtual Expression ExecuteInsert(OInsertCommandExpression insert, QueryCommand command, Expression[] values)
        {
            var reader = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);
            var saveScope = this.scope;

            var projection = this.Linguist.Translator.Mapper.GetQueryExpression(new OMappingEntity(insert.Projection.Projector.Type, _repoType));
            var fields = new OFieldFinder().Find(insert.Projection.Projector).Select(fe => new FieldDeclaration(fe.Name, fe, fe.QueryType)).ToArray();
            var alias = ((FieldExpression)fields[0].Expression).Alias;
            this.scope = new BuilderScope(
                this.scope,
                reader,
                alias,
                fields)
            {
                UseOrdinalMapping = false // we can't guarantee the order that properties will be returned, so we need to read by name
            };
            //var projector = Expression.Lambda(this.Visit(insert.Projection.Projector), reader);
            var projector = RedirectProjector(insert.Projection.Projector, reader, false);
            this.scope = saveScope;

            var entity = EntityFinder.Find(insert.Projection.Projector);

            // call low-level execute directly on supplied DbQueryProvider
            Expression result = Expression.Call(this.Executor, "Execute", new Type[] { insert.Identifiable.Entity.EntityType },
                Expression.Constant(command),
                projector,
                Expression.Constant(entity, typeof(MappingEntity)),
                Expression.NewArrayInit(typeof(object), values)
                );

            if (insert.Projection.Aggregator != null)
            {
                // apply aggregator
                result = DbExpressionReplacer.Replace(insert.Projection.Aggregator.Body, insert.Projection.Aggregator.Parameters[0], result);
            }
            return result;
        }