コード例 #1
0
ファイル: OTypeMapper.cs プロジェクト: PaybackMan/Cinder
        public override Expression GetUpdateExpression(IMappedEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, ((OTypeMapping)this.Mapping).GetTableName(entity));

            var where = this.GetIdentityCheck(table, entity, instance);
            if (updateCheck != null)
            {
                Expression typeProjector = this.GetEntityExpression(table, entity);
                Expression pred = DbExpressionReplacer.Replace(updateCheck.Body, updateCheck.Parameters[0], typeProjector);
                where = where.And(pred);
            }

            var assignments = this.GetFieldAssignments(table, instance, entity, (e, m) => ((OTypeMapping)this.Mapping).IsUpdatable(e, m));

            Expression update = new UpdateCommandExpression(table, where, assignments);

            if (selector != null)
            {
                return CreateUpdateCommand(entity, instance, selector, where, assignments);
            }
            else
            {
                return update;
            }
        }
コード例 #2
0
 protected DeleteCommandExpression UpdateDelete(DeleteCommandExpression delete, IdentifiableExpression table, Expression where)
 {
     if (table != delete.Identifiable || where != delete.Where)
     {
         return new DeleteCommandExpression(table, where);
     }
     return delete;
 }
コード例 #3
0
ファイル: OQueryBinder.cs プロジェクト: PaybackMan/Cinder
 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;
 }
コード例 #4
0
ファイル: OQueryBinder.cs プロジェクト: PaybackMan/Cinder
 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;
 }
コード例 #5
0
ファイル: OTypeMapper.cs プロジェクト: PaybackMan/Cinder
        public override Expression GetInsertExpression(IMappedEntity entity, Expression instance, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, ((OTypeMapping)this.Mapping).GetTableName(entity));
            var assignments = this.GetFieldAssignments(table, instance, entity, (e, m) => !((OTypeMapping)this.Mapping).IsGenerated(e, m));

            if (selector != null)
            {
                return CreateInsertCommand(entity, instance, selector, assignments);
            }

            return new InsertCommandExpression(table, assignments);
        }
コード例 #6
0
ファイル: BasicMapper.cs プロジェクト: PaybackMan/Cinder
        public override Expression GetDeleteExpression(IMappedEntity entity, Expression instance, LambdaExpression deleteCheck)
        {
            IdentifiableExpression table = new IdentifiableExpression(new IdentifiableAlias(), entity, this.mapping.GetTableName(entity));
            Expression where = null;

            if (instance != null)
            {
                where = this.GetIdentityCheck(table, entity, instance);
            }

            if (deleteCheck != null)
            {
                Expression row = this.GetEntityExpression(table, entity);
                Expression pred = DbExpressionReplacer.Replace(deleteCheck.Body, deleteCheck.Parameters[0], row);
                where = (where != null) ? where.And(pred) : pred;
            }

            return new DeleteCommandExpression(table, where);
        }
コード例 #7
0
ファイル: OTypeMapper.cs プロジェクト: PaybackMan/Cinder
        private OUpdateCommandExpression CreateUpdateCommand(IMappedEntity entity, 
            Expression instance, LambdaExpression selector, Expression where, IEnumerable<FieldAssignment> assignments)
        {
            var identifiableAlias = new IdentifiableAlias();
            var tex = new IdentifiableExpression(identifiableAlias, entity, ((OTypeMapping)this.Mapping).GetTableName(entity));
            Expression typeProjector = this.GetEntityExpression(tex, entity);
            Expression selection = DbExpressionReplacer.Replace(selector.Body, selector.Parameters[0], typeProjector);
            IdentifiableAlias newAlias = new IdentifiableAlias();
            var pc = FieldProjector.ProjectFields(this.Translator.Linguist.Language, selection, null, newAlias, identifiableAlias);

            return new OUpdateCommandExpression(tex, where, assignments, pc.Projector);
        }
コード例 #8
0
 protected virtual Expression VisitIdentifiable(IdentifiableExpression table)
 {
     return table;
 }
コード例 #9
0
 protected UpdateCommandExpression UpdateUpdate(UpdateCommandExpression update, IdentifiableExpression table, Expression where, IEnumerable<FieldAssignment> assignments)
 {
     if (table != update.Identifiable || where != update.Where || assignments != update.Assignments)
     {
         return new UpdateCommandExpression(table, where, assignments);
     }
     return update;
 }
コード例 #10
0
 protected override Expression VisitIdentifiable(IdentifiableExpression table)
 {
     this.aliases.Add(table.Alias);
     return table;
 }
コード例 #11
0
ファイル: BasicMapper.cs プロジェクト: PaybackMan/Cinder
        protected virtual Expression GetInsertResult(IMappedEntity entity, Expression instance, LambdaExpression selector, Dictionary<MemberInfo, Expression> map)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var tex = new IdentifiableExpression(IdentifiableAlias, entity, this.mapping.GetTableName(entity));
            var aggregator = Aggregator.GetAggregator(selector.Body.Type, typeof(IEnumerable<>).MakeGenericType(selector.Body.Type));

            Expression where;
            DeclarationCommand genIdCommand = null;
            var generatedIds = this.mapping.GetMappedMembers(entity).Where(m => this.mapping.IsPrimaryKey(entity, m) && this.mapping.IsGenerated(entity, m)).ToList();
            if (generatedIds.Count > 0)
            {
                if (map == null || !generatedIds.Any(m => map.ContainsKey(m)))
                {
                    var localMap = new Dictionary<MemberInfo, Expression>();
                    genIdCommand = this.GetGeneratedIdCommand(entity, generatedIds.ToList(), localMap);
                    map = localMap;
                }

                // is this just a retrieval of one generated id member?
                var mex = selector.Body as MemberExpression;
                if (mex != null && this.mapping.IsPrimaryKey(entity, mex.Member) && this.mapping.IsGenerated(entity, mex.Member))
                {
                    if (genIdCommand != null)
                    {
                        // just use the select from the genIdCommand
                        return new ProjectionExpression(
                            genIdCommand.Source,
                            new FieldExpression(mex.Type, genIdCommand.Variables[0].QueryType, genIdCommand.Source.Alias, genIdCommand.Source.Fields[0].Name),
                            aggregator
                            );
                    }
                    else
                    {
                        IdentifiableAlias alias = new IdentifiableAlias();
                        var colType = this.GetFieldType(entity, mex.Member);
                        return new ProjectionExpression(
                            new SelectExpression(alias, new[] { new FieldDeclaration("", map[mex.Member], colType) }, null, null),
                            new FieldExpression(TypeHelper.GetMemberType(mex.Member), colType, alias, ""),
                            aggregator
                            );
                    }
                }

                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);
            }

            Expression typeProjector = this.GetEntityExpression(tex, entity);
            Expression selection = DbExpressionReplacer.Replace(selector.Body, selector.Parameters[0], typeProjector);
            IdentifiableAlias newAlias = new IdentifiableAlias();
            var pc = FieldProjector.ProjectFields(this.translator.Linguist.Language, selection, null, newAlias, IdentifiableAlias);
            var pe = new ProjectionExpression(
                new SelectExpression(newAlias, pc.Fields, tex, where),
                pc.Projector,
                aggregator
                );

            if (genIdCommand != null)
            {
                return new BlockCommandExpression(genIdCommand, pe);
            }
            return pe;
        }
コード例 #12
0
ファイル: BasicMapper.cs プロジェクト: PaybackMan/Cinder
        public override Expression GetUpdateExpression(IMappedEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, this.mapping.GetTableName(entity));

            var where = this.GetIdentityCheck(table, entity, instance);
            if (updateCheck != null)
            {
                Expression typeProjector = this.GetEntityExpression(table, entity);
                Expression pred = DbExpressionReplacer.Replace(updateCheck.Body, updateCheck.Parameters[0], typeProjector);
                where = where.And(pred);
            }

            var assignments = this.GetFieldAssignments(table, instance, entity, (e, m) => this.mapping.IsUpdatable(e, m));

            Expression update = new UpdateCommandExpression(table, where, assignments);

            if (selector != null)
            {
                return new BlockCommandExpression(
                    update,
                    new IfCommandExpression(
                        this.translator.Linguist.Language.GetRowsAffectedExpression(update).GreaterThan(Expression.Constant(0)),
                        this.GetUpdateResult(entity, instance, selector),
                        null
                        )
                    );
            }
            else
            {
                return update;
            }
        }
コード例 #13
0
ファイル: BasicMapper.cs プロジェクト: PaybackMan/Cinder
        public override ProjectionExpression GetQueryExpression(IMappedEntity entity)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var selectAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, this.mapping.GetTableName(entity));

            Expression projector = this.GetEntityExpression(table, entity);
            var pc = FieldProjector.ProjectFields(this.translator.Linguist.Language, projector, null, selectAlias, IdentifiableAlias);

            var proj = new ProjectionExpression(
                new SelectExpression(selectAlias, pc.Fields, table, null),
                pc.Projector
                );

            return (ProjectionExpression)this.Translator.Police.ApplyPolicy(proj, entity.EntityType);
        }
コード例 #14
0
ファイル: BasicMapper.cs プロジェクト: PaybackMan/Cinder
        public override Expression GetInsertExpression(IMappedEntity entity, Expression instance, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, this.mapping.GetTableName(entity));
            var assignments = this.GetFieldAssignments(table, instance, entity, (e, m) => !this.mapping.IsGenerated(e, m));

            if (selector != null)
            {
                return new BlockCommandExpression(
                    new InsertCommandExpression(table, assignments),
                    this.GetInsertResult(entity, instance, selector, null)
                    );
            }

            return new InsertCommandExpression(table, assignments);
        }
コード例 #15
0
ファイル: QueryDuplicator.cs プロジェクト: PaybackMan/Cinder
 protected override Expression VisitIdentifiable(IdentifiableExpression table)
 {
     IdentifiableAlias newAlias = new IdentifiableAlias();
     this.map[table.Alias] = newAlias;
     return new IdentifiableExpression(newAlias, table.Entity, table.Name);
 }
コード例 #16
0
 protected virtual InsertCommandExpression UpdateInsert(InsertCommandExpression insert, IdentifiableExpression table, IEnumerable<FieldAssignment> assignments)
 {
     if (table != insert.Identifiable || assignments != insert.Assignments)
     {
         return new InsertCommandExpression(table, assignments);
     }
     return insert;
 }
コード例 #17
0
 protected virtual bool CompareIdentifiable(IdentifiableExpression a, IdentifiableExpression b)
 {
     return a.Name == b.Name;
 }