/// <summary> /// Main entry for generation purpose. /// </summary> /// <param name="connectionStringName">Connection string name stored in configuration file.</param> public void GenerateFromDb(string connectionStringName) { dbConfig = new DotWebDb(); EnsureApp(dbConfig); Inspect(connectionStringName); GenerateNavigationModules(dbConfig); SaveToConfig(true); DetermineColumnForLookUpDisplay(dbConfig); SaveToConfig(true); dbConfig.Dispose(); }
public void Generate(string assemblyName) { try { dbApp = GetDbContextFromAssembly(assemblyName); if (dbApp == null) { throw new ArgumentException("ERROR: There is no dbContext descendant class in the assembly."); } dbConfig = new DotWebDb(); if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["appId"])) { throw new ArgumentException("ERROR: appId must be specified in config."); } appId = int.Parse(ConfigurationManager.AppSettings["appId"]); app = dbConfig.Apps.Find(appId); if (app == null) { throw new ArgumentException(string.Format("ERROR: appId {0} not found in configdb.", appId)); } EnsureOutputDirectory(); EnsureTemplateDirectory(); EmptyOutputDirectory(); DeleteExistingNavigation(); var properties = dbApp.GetDbSetProperties(); var entitySets = properties.ToDictionary(x => x.Name, x => x.GetValue(dbApp, null)); if (entitySets.Count() == 0) { Console.WriteLine("WARNING: No entities in dbContext!"); } else { foreach (var entitySetName in entitySets.Keys) { var entityType = GetEntityTypeFromEntitySet(entitySets[entitySetName]); InspectEntity(entitySetName, entityType); } foreach (var entitySetName in entitySets.Keys) { var entityType = GetEntityTypeFromEntitySet(entitySets[entitySetName]); if (!entitiesMeta[entityType.Name].IsScaffold) { continue; } ReinspectEntity(entityType); } foreach (var entitySetName in entitySets.Keys) { var entityType = GetEntityTypeFromEntitySet(entitySets[entitySetName]); if (!entitiesMeta[entityType.Name].IsScaffold) { continue; } ProcessEntity(entitySetName, entitiesMeta[entityType.Name]); } } } finally { if (dbConfig != null) { dbConfig.Dispose(); } if (dbApp != null) { dbApp.Dispose(); } } }