Example #1
0
 protected virtual UpdateCommandExpression UpdateUpdate(OUpdateCommandExpression update, IdentifiableExpression table, Expression where,
     IEnumerable<FieldAssignment> assignments, ProjectionExpression projection)
 {
     if (table != update.Identifiable || where != update.Where || assignments != update.Assignments || projection.Projector != update.Projection.Projector)
     {
         return new OUpdateCommandExpression(table, where, assignments, projection.Projector);
     }
     return update;
 }
Example #2
0
        private Expression ExecuteUpdate(OUpdateCommandExpression update, 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(update.Projection.Projector.Type, _repoType));
            var fields = new OFieldFinder().Find(update.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(update.Projection.Projector), reader);
            var projector = RedirectProjector(update.Projection.Projector, reader, false);
            this.scope = saveScope;

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

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

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