Esempio n. 1
0
 public DbVersionInfo(EntityApp app, DbModelConfig config)
 {
     Version = app.Version;
       foreach (var m in app.Modules) {
     var schema = config.GetSchema(m.Area);
     Modules.Add(new ModuleDbVersionInfo(schema, m.Name, m.Version));
       }
 }
Esempio n. 2
0
 public DbVersionInfo(EntityApp app, DbModelConfig config)
 {
     Version = app.Version;
     foreach (var m in app.Modules)
     {
         var schema = config.GetSchema(m.Area);
         Modules.Add(new ModuleDbVersionInfo(schema, m.Name, m.Version));
     }
 }
Esempio n. 3
0
 /// <summary>Constructs DbModel from EntityModel.</summary>
 /// <param name="entityApp"></param>
 /// <param name="config"></param>
 internal DbModel(EntityApp entityApp, DbModelConfig config)
 {
     Util.Check(entityApp != null, "entityApp parameter may not be null.");
     EntityApp = entityApp;
     Config    = config;
     //Add schemas
     foreach (var area in entityApp.Areas)
     {
         Schemas.Add(new DbSchemaInfo(this, area, config.GetSchema(area)));
     }
     VersionInfo = new DbVersionInfo(EntityApp, Config);
 }
Esempio n. 4
0
 /// <summary>Constructs DbModel from EntityModel.</summary>
 /// <param name="entityApp"></param>
 /// <param name="config"></param>
 public DbModel(EntityApp entityApp, DbModelConfig config) : this(config) {
     Util.Check(entityApp != null, "entityApp parameter may not be null.");
     EntityApp = entityApp;
     //Add schemas
     foreach (var area in entityApp.Areas)
     {
         Schemas.Add(new DbSchemaInfo(this, config.GetSchema(area)));
     }
     VersionInfo = new DbVersionInfo(EntityApp, Config);
     var nullEnt = EntityApp.Model.NullEntityInfo;
     _nullTable = new DbTableInfo(this, null, "!!NullTable", nullEnt);
 }
Esempio n. 5
0
        }//method

        //Create tables and regular "value" columns
        private void BuildTables()
        {
            var supportsViews = _dbModel.Driver.Supports(DbFeatures.Views);

            foreach (var entity in _entityModel.Entities)
            {
                if (!IsActive(entity.Area))
                {
                    continue;
                }
                if (entity.Kind == EntityKind.View && !supportsViews)
                {
                    continue;
                }
                var tableName = GetDbTableViewName(entity);
                var objType   = entity.Kind == EntityKind.Table ? DbObjectType.Table : DbObjectType.View;
                var schema    = _dbModelConfig.GetSchema(entity.Area);
                var table     = new DbTableInfo(_dbModel, schema, tableName, entity, objType);
                // Check materialized view - automatically set the flag if there are indexes on the view
                if (entity.Kind == EntityKind.View)
                {
                    if (_driver.Supports(DbFeatures.MaterializedViews) && entity.ViewDefinition.Options.IsSet(DbViewOptions.Materialized))
                    {
                        table.IsMaterializedView = true;
                    }
                }
                //create Value columns
                foreach (var member in entity.Members)
                {
                    if (member.Kind == EntityMemberKind.Column)
                    {
                        CreateDbColumn(table, member);
                    }
                }
                //reorder DbColumns, make PK appear first
                var pkColumns = table.Columns.Where(c => c.Member.Flags.IsSet(EntityMemberFlags.PrimaryKey)).ToList();
                foreach (var pkCol in pkColumns)
                {
                    table.Columns.Remove(pkCol);
                    table.Columns.Insert(0, pkCol);
                }
                //order by
                if (entity.DefaultOrderBy != null)
                {
                    table.DefaultOrderBy = ConstructDefaultOrderBy(table);
                }
            }//foreach entityInfo
            CheckErrors();
        }