Esempio n. 1
0
        internal static string CreateObjectsScript(StoreItemCollection itemCollection, bool createSchemas)
        {
            var builder = new SqlDdlBuilder();

            foreach (var container in itemCollection.GetItems <EntityContainer>())
            {
                var entitySets = container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name);

                if (createSchemas)
                {
                    var schemas = new HashSet <string>(entitySets.Select(s => GetSchemaName(s)));
                    foreach (var schema in schemas.OrderBy(s => s))
                    {
                        // don't bother creating default schema
                        if (schema != "dbo")
                        {
                            builder.AppendCreateSchema(schema);
                        }
                    }
                }

                foreach (var entitySet in container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name))
                {
                    builder.AppendCreateTable(entitySet);
                }

                foreach (var associationSet in container.BaseEntitySets.OfType <AssociationSet>().OrderBy(s => s.Name))
                {
                    builder.AppendCreateForeignKeys(associationSet);
                }
            }
            return(builder.GetCommandText());
        }
Esempio n. 2
0
        internal static string CreateObjectsScript(
            StoreItemCollection itemCollection,
            bool createSchemas)
        {
            SqlDdlBuilder sqlDdlBuilder = new SqlDdlBuilder();

            foreach (EntityContainer entityContainer in itemCollection.GetItems <EntityContainer>())
            {
                IOrderedEnumerable <EntitySet> source = entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name));
                if (createSchemas)
                {
                    foreach (string schema in (IEnumerable <string>) new HashSet <string>(source.Select <EntitySet, string>((Func <EntitySet, string>)(s => SqlDdlBuilder.GetSchemaName(s)))).OrderBy <string, string>((Func <string, string>)(s => s)))
                    {
                        if (schema != "dbo")
                        {
                            sqlDdlBuilder.AppendCreateSchema(schema);
                        }
                    }
                }
                foreach (EntitySet entitySet in (IEnumerable <EntitySet>)entityContainer.BaseEntitySets.OfType <EntitySet>().OrderBy <EntitySet, string>((Func <EntitySet, string>)(s => s.Name)))
                {
                    sqlDdlBuilder.AppendCreateTable(entitySet);
                }
                foreach (AssociationSet associationSet in (IEnumerable <AssociationSet>)entityContainer.BaseEntitySets.OfType <AssociationSet>().OrderBy <AssociationSet, string>((Func <AssociationSet, string>)(s => s.Name)))
                {
                    sqlDdlBuilder.AppendCreateForeignKeys(associationSet);
                }
            }
            return(sqlDdlBuilder.GetCommandText());
        }