Exemple #1
0
 public void Execute()
 {
     foreach (var t in schema.Tables)
     {
         table        = t;
         classBuilder = new ClassBuilder();
         var implementationText = Write();
         CodeWriterUtils.WriteClassFile(codeWriterSettings.OutputDirectory, CodeWriterUtils.GetRepositoryInterfaceName(table), implementationText);
     }
 }
Exemple #2
0
        private void WriteRegisterRepositories()
        {
            using (classBuilder.BeginNest($"public static IServiceCollection AddEnterpriseDataRepositories(this IServiceCollection services)"))
            {
                foreach (var t in schema.Tables)
                {
                    var interfaceName      = CodeWriterUtils.GetRepositoryInterfaceName(t);
                    var implementationName = CodeWriterUtils.GetRepositoryImplementationName(t);
                    classBuilder.AppendLine($"services.AddTransient<{interfaceName}, {implementationName}>();");
                }

                classBuilder.AppendLine("return services;");
            }

            classBuilder.AppendLine("");
        }
Exemple #3
0
        public static IEnumerable <Parameter> GetTablesAsParameters(IEnumerable <DatabaseTable> tables)
        {
            var fields = new List <Parameter>();

            foreach (var t in tables.Distinct().OrderBy(t => t.Name))
            {
                var field = new Parameter
                {
                    ColumnNameToQueryBy = null,
                    DataType            = CodeWriterUtils.GetRepositoryInterfaceName(t),
                    Name = NameFixer.ToCamelCase(CodeWriterUtils.GetRepositoryImplementationName(t))
                };

                fields.Add(field);
            }

            return(fields);
        }
Exemple #4
0
        private string Write()
        {
            if (string.IsNullOrEmpty(table.NetName) && table.DatabaseSchema != null)
            {
                PrepareSchemaNames.Prepare(table.DatabaseSchema, codeWriterSettings.Namer);
            }

            CodeWriterUtils.WriteFileHeader(classBuilder);
            WriteUsings();
            CodeWriterUtils.BeginNestNamespace(classBuilder, codeWriterSettings);
            var tableOrView         = table is DatabaseView ? "view" : "table";
            var comment             = $"Interface providing repository CRUD operations for the {table.Name} {tableOrView}";
            var interfaceDefinition = $"public partial interface {CodeWriterUtils.GetRepositoryInterfaceName(table)}";

            classBuilder.AppendXmlSummary(comment);
            classBuilder.BeginNest(interfaceDefinition);
            WriteInterfaceMembers();
            classBuilder.EndNest(); // interface
            classBuilder.EndNest(); // namespace
            return(classBuilder.ToString());
        }