Пример #1
0
        public void Generate(Stream outStream)
        {
            if (outStream == null)
                throw new ArgumentNullException("outStream");

            if (DataSchema == null)
                throw new InvalidOperationException("DatabaseSchema property has not been set");

            if (DatabaseTargetSystem == null)
                throw new InvalidOperationException("DatabaseTargetSystem property has not been set");

            if (DatabaseColumnTypeMapper == null)
                throw new InvalidOperationException("ColumnTypeMapper property has not been set");

            Verification.VerificationContext context = new Verification.VerificationContext();
            DataSchema.Verify(context);
            if (context.HasErrors)
            {
                throw new InvalidOperationException("The DataSchema has verification errors");
            }

            using (StreamWriter writer = new StreamWriter(outStream, Encoding.UTF8))
            {
                WritePrologue(writer);
                foreach (Table table in DataSchema.Tables)
                {
                    WriteTable(writer, table);
                }
                WriteEpilogue(writer);
            }
        }
Пример #2
0
        public void Generate(Stream outStream)
        {
            if (outStream == null)
                throw new ArgumentNullException("outStream");

            if (DataSchema == null)
                throw new InvalidOperationException("DatabaseSchema property has not been set");

            if (TargetSystem == null)
                throw new InvalidOperationException("TargetSystem property has not been set");

            effectiveDatabaseSchemaName = DatabaseSchemaName;
            if (string.IsNullOrWhiteSpace(effectiveDatabaseSchemaName))
            {
                effectiveDatabaseSchemaName = "dbo";
            }

            Verification.VerificationContext context = new Verification.VerificationContext();
            DataSchema.Verify(context);
            if (context.HasErrors)
            {
                throw new InvalidOperationException("The DataSchema has verification errors");
            }

            using (StreamWriter writer = new StreamWriter(outStream))
            {
                WriteHeader(writer);

                foreach (Table table in DataSchema.Tables)
                {
                    if (table.Settings.GetValueAsBool(TargetSystem.Name, "Ignore"))
                        continue;
                    WriteTable(writer, table);
                    WritePrimaryKey(writer, table);
                    WriteIndices(writer, table);
                    WriteGo(writer);
                }

                foreach (Table table in DataSchema.Tables)
                {
                    if (table.Settings.GetValueAsBool(TargetSystem.Name, "Ignore"))
                        continue;
                    WriteReferences(writer, table);
                    WriteGo(writer);
                }

            }
        }
Пример #3
0
        public void Generate(Stream outStream)
        {
            if (outStream == null)
                throw new ArgumentNullException("outStream");

            if (DataSchema == null)
                throw new InvalidOperationException("DatabaseSchema property has not been set");

            if (TargetSystem == null)
                throw new InvalidOperationException("TargetSystem property has not been set");

            Verification.VerificationContext context = new Verification.VerificationContext();
            DataSchema.Verify(context);
            if (context.HasErrors)
            {
                throw new InvalidOperationException("The DataSchema has verification errors");
            }

            using (StreamWriter writer = new StreamWriter(outStream))
            {
                WriteHeader(writer);

                foreach (Table table in DataSchema.Tables)
                {
                    if (table.Settings.GetValueAsBool(TargetSystem.Name, "Ignore"))
                        continue;

                    var primaryKeyGeneratedColumn = GetDbGeneratedPrimaryKeyColumn(table);
                    if (primaryKeyGeneratedColumn != null)
                    {
                        WriteSequence(writer, table);
                    }
                    WriteTable(writer, table);
                    WriteGo(writer);

                    WriteNonUniqueIndices(writer, table);

                    if (ScriptDocumentGenerator != null)
                    {
                        ScriptDocumentGenerator.WriteDocumentation(DatabaseSchemaName, writer, table);
                    }

                    if (primaryKeyGeneratedColumn != null)
                    {
                        WriteSequenceTrigger(writer, table, primaryKeyGeneratedColumn);
                        WriteGo(writer);
                    }
                }

                //foreach (Table table in DataSchema.Tables)
                //{
                //    if (table.Settings.GetValueAsBool(TargetSystem.Name, "Ignore"))
                //        continue;
                //    WriteReferences(writer, table);
                //    WriteGo(writer);
                //}
            }
        }
Пример #4
0
        public void Generate(Stream outStream)
        {
            if (outStream == null)
                throw new ArgumentNullException("outStream");

            if (DataSchema == null)
                throw new InvalidOperationException("DatabaseSchema property has not been set");

            if (TargetSystem == null)
                throw new InvalidOperationException("TargetSystem property has not been set");

            if (DatabaseTargetSystem == null)
                throw new InvalidOperationException("DatabaseTargetSystem property has not been set");

            if (DatabaseColumnTypeMapper == null)
                throw new InvalidOperationException("ColumnTypeMapper property has not been set");

            Verification.VerificationContext context = new Verification.VerificationContext();
            DataSchema.Verify(context);
            if (context.HasErrors)
            {
                throw new InvalidOperationException("The DataSchema has verification errors");
            }

            var document =
                new XDocument
                (
                    new XDeclaration("1.0", "utf-8", null),
                    //<Database Name="GameCore" Class="DatabaseDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
                    new XElement
                    (
                        XName.Get("Database", xmlNamespace),
                        new XAttribute("Name", DataSchema.Name),
                        new XAttribute("Class", DataSchema.Name + "DataContext"),
                        GenerateConnection(),
                        GenerateTables()
                    )
                );

            using (StreamWriter writer = new StreamWriter(outStream, Encoding.UTF8))
            {
                document.Save(writer);
            }
        }