Exemplo n.º 1
0
        public override void WriteToStream(IndentStream stream)
        {
            if (!string.IsNullOrEmpty(JoinType))
            {
                stream.Write($"{JoinType.ToUpper()} ");
            }

            if (!string.IsNullOrEmpty(OuterType))
            {
                stream.Write($"{OuterType.ToUpper()} ");
            }

            stream.Write("JOIN ");

            SecondTable.WriteToStream(stream);
            if (AliasName != null)
            {
                stream.Write(" ");
                AliasName.WriteToStream(stream);
            }

            if (WithOptions != null && WithOptions.Count > 0)
            {
                stream.Write(" WITH(");
                WithOptions.ToUpper().WriteToStreamWithComma(stream);
                stream.Write(")");
            }

            if (JoinOnExpr != null)
            {
                stream.Write(" ON ");
                JoinOnExpr.WriteToStream(stream);
            }
        }
Exemplo n.º 2
0
		public override void WriteToStream(IndentStream stream)
		{
			stream.Write("DELETE");

			if (TopExpr != null)
			{
				stream.Write(" ");
				TopExpr.WriteToStream(stream);
			}

			stream.Write(" FROM ");
			Table.WriteToStream(stream);

			if (WithOptions != null && WithOptions.Count > 0)
			{
				stream.Write(" WITH(");
				WithOptions.WriteToStreamWithComma(stream);
				stream.Write(")");
			}

			if (OutputList != null && OutputList.Count > 0)
			{
				stream.WriteLine();
				stream.Write("OUTPUT ");
				OutputList.WriteToStreamWithComma(stream);
			}

			if (IntoTableExpr != null)
			{
				stream.WriteLine();
				IntoTableExpr.WriteToStream(stream);
			}

			if (OutputList1 != null && OutputList1.Count > 0)
			{
				stream.WriteLine();
				stream.Write("OUTPUT ");
				OutputList.WriteToStreamWithComma(stream);
			}

			if (FromSourceList != null && FromSourceList.Count > 0)
			{
				stream.WriteLine();
				stream.Write("FROM ");
				FromSourceList.WriteToStreamWithComma(stream);
			}

			if (WhereExpr != null)
			{
				stream.WriteLine();
				stream.Write("WHERE ");
				WhereExpr.WriteToStream(stream);
			}

			if (OptionExpr != null)
			{
				stream.WriteLine();
				OptionExpr.WriteToStream(stream);
			}
		}
Exemplo n.º 3
0
        public override void WriteToStream(IndentStream stream)
        {
            stream.Write("MERGE");

            if (!string.IsNullOrEmpty(IntoToken))
            {
                stream.Write($" {IntoToken}");
            }

            stream.Write(" ");
            TargetTable.WriteToStream(stream);

            if (WithOptions != null && WithOptions.Count > 0)
            {
                stream.Write(" WITH(");
                WithOptions.WriteToStreamWithComma(stream);
                stream.Write(")");
            }

            if (TargetTableAliasName != null)
            {
                stream.Write(" AS ");
                TargetTableAliasName.WriteToStream(stream);
            }

            stream.WriteLine();
            stream.Write("USING ");
            TableSource.WriteToStream(stream);

            if (TableSourceAliasName != null)
            {
                stream.Write(" AS ");
                TableSourceAliasName.WriteToStream(stream);
            }

            if (SourceColumnList != null && SourceColumnList.Count > 0)
            {
                stream.Write("(");
                SourceColumnList.WriteToStreamWithComma(stream);
                stream.Write(")");
            }

            stream.Write(" ON ");
            OnMergeSearchCondition.WriteToStream(stream);

            if (WhenList != null && WhenList.Count > 0)
            {
                stream.WriteLine();
                WhenList.WriteToStream(stream);
            }

            if (OutputList != null && OutputList.Count > 0)
            {
                stream.WriteLine();
                stream.Write("OUTPUT ");
                OutputList.WriteToStreamWithComma(stream);
            }

            stream.Write(" ;");
        }
        public BuildingReferenceInfo AppendReference(Expression propExpr, WithOptions withOpts = null)
        {
            var memberName    = (propExpr as MemberExpression).Member.Name;
            var referenceProp = this.MetaClass[memberName];
            var joinedClass   = MetaFactory.Default.GetClass(referenceProp.PropertyType);

            var referenceTable = new BuildingJoinableTableInfo(joinedClass);

            referenceTable.Tablename  = withOpts?.Tablename ?? Builder.GetTablename(joinedClass);
            referenceTable.Fieldnames = withOpts?.Fieldnames;

            if (withOpts != null && withOpts.References != null)
            {
                foreach (var join in withOpts.References)
                {
                    var refc = referenceTable.AppendReference(join.PropertyExpression, join.WithOpts);
                    if (join.IsMany)
                    {
                        refc.ReferenceType = refc.InterTable == null ? ReferenceTypes.WithMany : ReferenceTypes.ManyMany;
                    }
                }
            }

            var reference = new BuildingReferenceInfo()
            {
                PrimaryKey         = (withOpts?.Primary?.Body as MemberExpression)?.Member?.Name ?? "Id",
                ForeignKey         = (withOpts?.Foreign?.Body as MemberExpression)?.Member?.Name ?? this.Tablename + "Id",
                ReferenceProperty  = referenceProp,
                ReferenceTableInfo = referenceTable
            };

            this.References.Add(memberName, reference);
            return(reference);
        }
Exemplo n.º 5
0
        public override void WriteToStream(IndentStream stream)
        {
            stream.Write("UPDATE");

            if (TopCount != null)
            {
                stream.Write(" ");
                TopCount.WriteToStream(stream);
            }

            if (Table != null)
            {
                stream.Write(" ");
                Table.WriteToStream(stream);
            }

            if (WithOptions != null && WithOptions.Count > 0)
            {
                stream.Write(" WITH(");
                WithOptions.WriteToStreamWithComma(stream);
                stream.Write(")");
            }

            stream.Write(" SET ");
            SetColumnsList.WriteToStreamWithComma(stream);

            if (OutputList != null && OutputList.Count > 0)
            {
                stream.WriteLine();
                stream.Write("OUTPUT ");
                OutputList.WriteToStreamWithComma(stream);
            }

            if (IntoExpr != null)
            {
                stream.WriteLine();
                IntoExpr.WriteToStream(stream);
            }

            if (FromTableList != null && FromTableList.Count > 0)
            {
                stream.WriteLine();
                stream.Write("FROM ");
                FromTableList.WriteToStreamWithComma(stream);
            }

            if (WhereExpr != null)
            {
                stream.WriteLine();
                stream.Write("WHERE ");
                WhereExpr.WriteToStream(stream);
            }
        }
Exemplo n.º 6
0
 public SuggestionOptionsBuilder(SuggestionOptions options)
 {
     _with  = options.With;
     _fuzzy = options.Fuzzy;
     _max   = options.Max;
 }
Exemplo n.º 7
0
            public SuggestionOptionsBuilder With(WithOptions with)
            {
                _with = with;

                return(this);
            }
Exemplo n.º 8
0
 public ISelectBuilder <T> WithMany <TForeign>(Expression <Func <T, IEnumerable <TForeign> > > propExpr, WithOptions <T, TForeign> withOpts = null)
 {
     this.RootTable.WithMany(propExpr, withOpts);
     return(this);
 }
        public BuildingJoinableTableInfo WithMany <TPrimary, TForeign>(Expression <Func <TPrimary, IEnumerable <TForeign> > > prop, WithOptions <TPrimary, TForeign> opts)
        {
            var reference = this.AppendReference(prop, opts);

            if (opts != null)
            {
                if (opts.InterTablename != null)
                {
                    reference.ReferenceType = ReferenceTypes.ManyMany;
                }
                else
                {
                    reference.ReferenceType = ReferenceTypes.WithMany;
                }
            }


            return(this);
        }
        public BuildingJoinableTableInfo WithOne <TPrimary, TForeign>(Expression <Func <TPrimary, TForeign> > prop, WithOptions <TPrimary, TForeign> opts)
        {
            var reference = this.AppendReference(prop, opts);

            reference.ReferenceType = ReferenceTypes.WithOne;
            //this.RootTable.References.Add(reference.ReferenceProperty.Name, reference);
            return(this);
        }