public override Statement CreateStatement(DatabaseMapper mapper)
        {
            var select = new SelectStatement();

            select.Source = new Table(mapper.GetTableName(this.Source.Type), this.Source.Alias);
            select.SourceFields.AddRange(this.SourceFields.Select(s => PropertyToSourceField(s, mapper)));
            select.SourceFields.AddRange(this.AggregateFields.Select(s => PropertyToAggregate(s, mapper)));
            select.IsAny      = this.IsAny;
            select.IsAll      = this.IsAll;
            select.IsDistinct = this.IsDistinct;
            select.StartIndex = this.StartIndex;
            select.Limit      = this.Limit;
            if (this.Conditions != null)
            {
                // TODO: Need to handle columns from multiple tables...
                var aliasTables = !string.IsNullOrEmpty(this.Source.Alias);
                foreach (var condition in StatementCreator.VisitStatementConditions(this.Conditions, mapper, aliasTables))
                {
                    select.Conditions.Add(condition);
                }
            }
            select.OrderByFields.AddRange(this.OrderByFields.Select(s => PropertyToOrderBy(s, mapper)));
            select.GroupByFields.AddRange(this.GroupByFields.Select(s => PropertyToGroupBy(s, mapper)));
            return(select);
        }
 private SetValue PropertyToSetValue(FieldValue sv, DatabaseMapper mapper)
 {
     return(new SetValue(
                new Column(
                    mapper.GetTableName(sv.Field.DeclaringType),
                    mapper.GetColumnName(sv.Field)),
                sv.Value));
 }
Exemple #3
0
        public InsertStatement CreateStatement(DatabaseMapper mapper)
        {
            var insert = new InsertStatement();

            insert.Target = new Table(mapper.GetTableName(this.Target));
            insert.SetValues.AddRange(this.SetValues.Select(sv => new SetValue(new Column(mapper.GetColumnName(sv.Item1)), sv.Item2)));
            return(insert);
        }
Exemple #4
0
        public override Statement CreateStatement(DatabaseMapper mapper)
        {
            var insert = new InsertStatement();

            insert.Target = new Table(mapper.GetTableName(this.Target));
            insert.SetValues.AddRange(this.SetValues.Select(sv => PropertyToSetValue(sv, mapper)));
            return(insert);
        }
Exemple #5
0
        public override Statement CreateStatement(DatabaseMapper mapper)
        {
            var delete = new DeleteStatement();

            delete.Target = new Table(mapper.GetTableName(this.Target));
            foreach (var condition in StatementCreator.VisitStatementConditions(this.Conditions, mapper, false))
            {
                delete.Conditions.Add(condition);
            }
            return(delete);
        }
 private string TableNameOrAlias(DatabaseMapper mapper, Type t)
 {
     if (t == this.Source.Type && !string.IsNullOrEmpty(this.Source.Alias))
     {
         return(this.Source.Alias);
     }
     else
     {
         return(mapper.GetTableName(t));
     }
 }
        public UpdateStatement CreateStatement(DatabaseMapper mapper)
        {
            var update = new UpdateStatement();

            update.Target = new Table(mapper.GetTableName(this.Target));
            update.SetValues.AddRange(this.SetValues.Select(sv => new SetValue(new Column(mapper.GetTableName(sv.Item1.DeclaringType), mapper.GetColumnName(sv.Item1)), sv.Item2)));
            foreach (var condition in StatementCreator.VisitStatementConditions(this.Conditions, mapper, false))
            {
                update.Conditions.Add(condition);
            }
            return(update);
        }
        public override Statement CreateStatement(DatabaseMapper mapper)
        {
            var update = new UpdateStatement();

            update.Target = new Table(mapper.GetTableName(this.Target));
            update.SetValues.AddRange(this.SetValues.Select(sv => PropertyToSetValue(sv, mapper)));
            foreach (var condition in StatementCreator.VisitStatementConditions(this.Conditions, mapper, false))
            {
                update.Conditions.Add(condition);
            }
            return(update);
        }
        public SelectStatement CreateStatement(DatabaseMapper mapper)
        {
            var select = new SelectStatement();

            select.Source = new Table(mapper.GetTableName(this.Source.Type), this.Source.Alias);
            select.SourceFields.AddRange(this.SourceFields.Select(s => new Column(TableNameOrAlias(mapper, s.DeclaringType), mapper.GetColumnName(s))));
            select.SourceFields.AddRange(this.AggregateFields.Select(s => new Aggregate(s.Item2, new Column(s.Item1 != null ? TableNameOrAlias(mapper, s.Item1.DeclaringType) : "", s.Item1 != null ? mapper.GetColumnName(s.Item1) : "*"))));
            select.IsAny      = this.IsAny;
            select.IsAll      = this.IsAll;
            select.IsDistinct = this.IsDistinct;
            select.StartIndex = this.StartIndex;
            select.Limit      = this.Limit;
            if (this.Conditions != null)
            {
                // TODO: Need to handle columns from multiple tables...
                var aliasTables = !string.IsNullOrEmpty(this.Source.Alias);
                foreach (var condition in StatementCreator.VisitStatementConditions(this.Conditions, mapper, aliasTables))
                {
                    select.Conditions.Add(condition);
                }
            }
            select.OrderByFields.AddRange(this.OrderByFields.Select(s => new OrderByExpression(new Column(TableNameOrAlias(mapper, s.Item1.DeclaringType), mapper.GetColumnName(s.Item1)), s.Item2)));
            return(select);
        }