protected override void VisitDbSchemaMetadata(DbSchemaMetadata item)
        {
            // this will write out the types and functions
            base.VisitDbSchemaMetadata(item);

            // this will write out the associations
            VisitForeignKeyConstraints(_foreignKeyConstraintList);

            // clear the constraints for this schema so we can use the collection again
            _foreignKeyConstraintList.Clear();
        }
 protected virtual void VisitDbSchemaMetadata(DbSchemaMetadata item)
 {
     VisitDbAliasedMetadataItem(item);
     if (item != null)
     {
         if (item.HasTables)
         {
             VisitCollection(item.Tables, VisitDbTableMetadata);
         }
     }
 }
 internal void WriteEntitySetElementHeader(DbSchemaMetadata containingSchema, DbTableMetadata entitySet)
 {
     _xmlWriter.WriteStartElement(SsdlConstants.Element_EntitySet);
     _xmlWriter.WriteAttributeString(SsdlConstants.Attribute_Name, entitySet.Name);
     _xmlWriter.WriteAttributeString(
         SsdlConstants.Attribute_EntityType, GetQualifiedTypeName(SsdlConstants.Value_Self, entitySet.Name));
     if (containingSchema.DatabaseIdentifier != null)
     {
         _xmlWriter.WriteAttributeString(SsdlConstants.Attribute_Schema, containingSchema.DatabaseIdentifier);
     }
     if (entitySet.DatabaseIdentifier != null)
     {
         _xmlWriter.WriteAttributeString(SsdlConstants.Attribute_Table, entitySet.DatabaseIdentifier);
     }
 }
            internal void Visit(DbDatabaseMetadata dbDatabase)
            {
                _containerSchemaWriter.WriteEntityContainerElementHeader(dbDatabase.Name);

                foreach (var dbSchema in dbDatabase.Schemas)
                {
                    currentSchema = dbSchema;
                    base.VisitDbSchemaMetadata(dbSchema);
                    currentSchema = null;
                }

                _containerSchemaWriter.WriteEndElement();
            }
        private static void ConfigureTable(
            DbDatabaseMetadata database, DbSchemaMetadata containingSchema, DbTableMetadata table)
        {
            //Contract.Requires(database != null);
            //Contract.Requires(containingSchema != null);
            //Contract.Requires(table != null);

            var tableName = table.GetTableName();

            if (tableName == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(tableName.Schema)
                && !string.Equals(containingSchema.Name, tableName.Schema, StringComparison.Ordinal))
            {
                containingSchema
                    = database.Schemas
                        .SingleOrDefault(s => string.Equals(s.Name, tableName.Schema, StringComparison.Ordinal));

                if (containingSchema == null)
                {
                    database.Schemas.Add(
                        containingSchema = new DbSchemaMetadata
                            {
                                Name = tableName.Schema,
                                DatabaseIdentifier = tableName.Schema
                            });
                }

                database.RemoveTable(table);
                containingSchema.Tables.Add(table);
            }

            if (!string.Equals(table.DatabaseIdentifier, tableName.Name, StringComparison.Ordinal))
            {
                table.DatabaseIdentifier = tableName.Name;
            }
        }