Example #1
0
        /// <summary>
        /// Get DbContext partial templates.
        /// </summary>
        /// <param name="language">Language option.</param>
        /// <returns>Partial templates.</returns>
        protected override IDictionary <string, string> GetPartialTemplates(
            LanguageOptions language = LanguageOptions.CSharp)
        {
            DbContextTemplateFiles.TryGetValue(Constants.DbContextImportTemplate, out TemplateFileInfo importFile);
            var importTemplateFile = FileService.RetrieveTemplateFileContents(
                importFile.RelativeDirectory, importFile.FileName);

            DbContextTemplateFiles.TryGetValue(Constants.DbContextCtorTemplate, out TemplateFileInfo ctorFile);
            var ctorTemplateFile = FileService.RetrieveTemplateFileContents(
                ctorFile.RelativeDirectory, ctorFile.FileName);

            DbContextTemplateFiles.TryGetValue(Constants.DbContextDbSetsTemplate, out TemplateFileInfo propertyFile);
            var propertyTemplateFile = FileService.RetrieveTemplateFileContents(
                propertyFile.RelativeDirectory, propertyFile.FileName);

            var templates = new Dictionary <string, string>
            {
                {
                    Constants.DbContextImportTemplate.ToLower(),
                importTemplateFile
                },
                {
                    Constants.DbContextCtorTemplate.ToLower(),
                ctorTemplateFile
                },
                {
                    Constants.DbContextDbSetsTemplate.ToLower(),
                propertyTemplateFile
                },
            };

            return(templates);
        }
Example #2
0
        /// <summary>
        /// Compile the DbContext template.
        /// </summary>
        /// <param name="language">Language option.</param>
        /// <returns>DbContext template.</returns>
        protected virtual Func <object, string> CompileDbContextTemplate(
            LanguageOptions language = LanguageOptions.CSharp)
        {
            DbContextTemplateFiles.TryGetValue(Constants.DbContextTemplate, out TemplateFileInfo contextFile);
            var contextTemplateFile = FileService.RetrieveTemplateFileContents(
                contextFile.RelativeDirectory, contextFile.FileName);
            var contextTemplate = HandlebarsLib.Compile(contextTemplateFile);

            return(contextTemplate);
        }