Exemple #1
0
        /// <summary>
        ///     Конфигурирует модель из B#
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public PersistentModel Setup(IBSharpContext context)
        {
            Context = context;
            IEnumerable <IBSharpClass> tables = Context.ResolveAll(TablePrototype + ";attr:" + TableAttribute).ToArray();

            foreach (IBSharpClass table in tables)
            {
                var pclass = new PersistentClass();
                pclass.Setup(table);
                pclass.Model = this;
                Classes[pclass.FullSqlName.ToLowerInvariant()] = pclass;
            }
            SetupDefaultScripts();
            foreach (SqlObject obj in SqlObject.CreateDatabaseWide(this))
            {
                DatabaseSqlObjects.Add(obj);
            }
            BuildModel();
            ReadScripts();
            return(this);
        }
Exemple #2
0
        private IEnumerable <object> GetCreateOrderedWriters(DbDialect dialect, ScriptMode mode = ScriptMode.Create)
        {
            foreach (SqlScript script in GetScripts(dialect, mode, ScriptPosition.Before))
            {
                yield return(script);
            }

            foreach (FileGroup fg in DatabaseSqlObjects.OfType <FileGroup>())
            {
                yield return(fg);
            }
            foreach (Schema schema in DatabaseSqlObjects.OfType <Schema>())
            {
                yield return(schema);
            }
            foreach (Sequence sequence in Tables.SelectMany(_ => _.SqlObjects.OfType <Sequence>()))
            {
                yield return(sequence);
            }
            foreach (PartitionDefinition part in Tables.SelectMany(_ => _.SqlObjects.OfType <PartitionDefinition>()))
            {
                yield return(part);
            }

            foreach (SqlScript script in GetScripts(dialect, mode, ScriptPosition.BeforeTables))
            {
                yield return(script);
            }
            foreach (PersistentClass cls in Tables)
            {
                yield return(cls);
            }
            foreach (Field circularRef in Tables.SelectMany(_ => _.Fields.Values.Where(__ => __.GetIsCircular())))
            {
                yield return(circularRef);
            }

            foreach (SqlScript script in GetScripts(dialect, mode, ScriptPosition.AfterTables))
            {
                yield return(script);
            }

            foreach (SqlFunction function in Tables.SelectMany(_ => _.SqlObjects.OfType <SqlFunction>()))
            {
                if (function.Dialect == DbDialect.None || function.Dialect == dialect || function.Dialect == DbDialect.Ansi)
                {
                    yield return(function);
                }
            }
            foreach (SqlView view in Tables.SelectMany(_ => _.SqlObjects.OfType <SqlView>()))
            {
                if (view.Dialect == DbDialect.None || view.Dialect == dialect || view.Dialect == DbDialect.Ansi)
                {
                    yield return(view);
                }
            }
            foreach (SqlTrigger trigger in Tables.SelectMany(_ => _.SqlObjects.OfType <SqlTrigger>()))
            {
                if (trigger.Dialect == DbDialect.None || trigger.Dialect == dialect || trigger.Dialect == DbDialect.Ansi)
                {
                    yield return(trigger);
                }
            }

            foreach (SqlScript script in Tables.SelectMany(_ => _.SqlObjects.OfType <SqlScript>()))
            {
                if (script.Dialect == DbDialect.None || script.Dialect == dialect || script.Dialect == DbDialect.Ansi)
                {
                    yield return(script);
                }
            }

            foreach (SqlScript script in GetScripts(dialect, mode, ScriptPosition.After))
            {
                yield return(script);
            }
        }