/// <summary>
        /// Validates whether the Entity Framework generator has any errors.
        /// </summary>
        /// <param name="gen">The EntityFrameworkGenerator generator.</param>
        /// <exception cref="WizardException"></exception>
        private static void TryErrorsEntityFrameworkGenerator(EntityFrameworkGenerator gen)
        {
            if (gen == null || gen.Errors.Count() == 0)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < gen.Errors.Count(); i++)
            {
                sb.Append(" - ").AppendLine(gen.Errors.ElementAt(i));
            }

            throw new WizardException(string.Format("The Entity Framework generation failed with the following errors:\n\n", sb.ToString()));
        }
 public ApplicationController(ApplicationPreferences applicationPreferences, Table table)
 {
     this.applicationPreferences = applicationPreferences;
     codeGenerator            = new CodeGenerator(applicationPreferences, table);
     fluentGenerator          = new FluentGenerator(applicationPreferences, table);
     entityFrameworkGenerator = new EntityFrameworkGenerator(applicationPreferences, table);
     castleGenerator          = new CastleGenerator(applicationPreferences, table);
     contractGenerator        = new ContractGenerator(applicationPreferences, table);
     byCodeGenerator          = new ByCodeGenerator(applicationPreferences, table);
     if (applicationPreferences.ServerType == ServerType.Oracle)
     {
         mappingGenerator = new OracleMappingGenerator(applicationPreferences, table);
     }
     else
     {
         mappingGenerator = new SqlMappingGenerator(applicationPreferences, table);
     }
 }
        /// <summary>
        /// Generates the entity framework model.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="vsProj">The Visual Studio project object.</param>
        /// <param name="connection">The MySql connection.</param>
        /// <param name="modelName">Name of the "edmx" model.</param>
        /// <param name="tables">The tables.</param>
        /// <param name="modelPath">The model path.</param>
        /// <param name="currentEntityFrameworkVersion">The current entity framework version.</param>
        /// <param name="language">The language generator (C# or VB.NET).</param>
        /// <param name="columnMappings">The column mappings.</param>
        /// <param name="tablesIncludedInModel">The tables included in model.</param>
        internal static void GenerateEntityFrameworkModel(Project project, VSProject vsProj, MySqlConnection connection, string modelName, List <string> tables, string modelPath,
                                                          string currentEntityFrameworkVersion, LanguageGenerator language, Dictionary <string, Dictionary <string, ColumnValidation> > columnMappings, ref Dictionary <string, string> tablesIncludedInModel)
        {
            if (project != null)
            {
                string projectNamespace = project.Properties.Item("DefaultNamespace").Value.ToString();
                string ns = GetCanonicalIdentifier(projectNamespace);
                EntityFrameworkGenerator gen = new EntityFrameworkGenerator(connection, modelName, tables, modelPath, ns, currentEntityFrameworkVersion, language, vsProj, columnMappings);
                vsProj = project.Object as VSProject;
                project.DTE.Solution.SolutionBuild.Build(true);
                string projectPath = Path.GetDirectoryName(project.FullName);
                gen.GenerateItemTemplates(projectPath, modelName);
                if (gen.TablesInModel.Count() > 0)
                {
                    tablesIncludedInModel = gen.TablesInModel.ToDictionary <string, string>(p => p);
                }

                TryErrorsEntityFrameworkGenerator(gen);
            }
        }