예제 #1
0
        public string GeneraSelectByPk()
        {
            MemoryStream  ms = new MemoryStream();
            CSourceWriter sw = new CSourceWriter(ms);

            this.GeneraSelectByPk(sw);
            sw.Close();
            return(Encoding.UTF8.GetString(ms.ToArray()));
        }
        public override void Generate(TextWriter lMensaje)
        {
            CSourceWriter sw = new CSourceWriter(this.ParentDirectory.FullName, this.Name);

            try {
                GenerateUsings(sw);
                GenerateNamespace(sw);
                foreach (CSharpElement item in this.lElement)
                {
                    item.Generate(sw);
                }
                GenerateEndNamespace(sw);
            } finally {
                sw.Close();
                lMensaje.WriteLine("Generado: " + sw.FullFileName);
            }
        }
예제 #3
0
        public string GenerateSql(bool withDrops)
        {
            MemoryStream  ms = new MemoryStream();
            CSourceWriter sw = new CSourceWriter(ms);

            if (withDrops)
            {
                //Primero se borran todas las relaciones para evitar errores de eliminación de tablas con otras relacionadas.(Si existen)
                foreach (CTableM t in this.lTable)
                {
                    foreach (CRelationM r in t.lRelation)
                    {
                        sw.WriteLn(string.Format("IF OBJECT_ID('dbo.{0}', 'F') IS NOT NULL ALTER TABLE dbo.{1} DROP CONSTRAINT {0};", r.Name, r.tableSource.Name));
                        sw.WriteLn("GO");
                    }
                }
                //Se elinan las tablas si existen
                foreach (CTableM t in this.lTable)
                {
                    sw.WriteLn(string.Format("IF OBJECT_ID('dbo.{0}', 'U') IS NOT NULL DROP TABLE dbo.{0};", t.Name));
                    sw.WriteLn("GO");
                }
            }
            foreach (CTableM t in this.lTable)
            {
                t.GenerateSql(sw);
                sw.EndLine();
            }

            foreach (CTableM t in this.lTable)
            {
                foreach (CRelationM r in t.lRelation)
                {
                    r.GeneraSql(sw);
                }
            }

            sw.Close();
            return(Encoding.UTF8.GetString(ms.ToArray()));
        }