Exemplo n.º 1
0
        public CodeOutput GeneratePocoConfiguration(Table table, Generator generator)
        {
            if (!CanWritePocoConfiguration())
            {
                return(null);
            }

            var columns = table.Columns
                          .Where(x => !x.Hidden && !string.IsNullOrEmpty(x.Config))
                          .OrderBy(x => x.Ordinal)
                          .ToList();

            var foreignKeys = columns.SelectMany(x => x.ConfigFk).OrderBy(o => o).ToList();

            var indexes    = _generator.IndexModelBuilder(table);
            var hasIndexes = indexes != null && indexes.Any();

            var data = new PocoConfigurationModel
            {
                Name = table.DbName,
                ConfigurationClassName  = table.NameHumanCaseWithSuffix() + Settings.ConfigurationClassName,
                NameHumanCaseWithSuffix = table.NameHumanCaseWithSuffix(),
                Schema = table.Schema.DbName,
                PrimaryKeyNameHumanCase = table.PrimaryKeyNameHumanCase(),
                HasSchema                 = !string.IsNullOrEmpty(table.Schema.DbName),
                ClassModifier             = Settings.EntityClassesModifiers,
                ClassComment              = table.WriteComments(),
                Columns                   = columns.Select(x => x.Config).ToList(),
                HasReverseNavigation      = table.ReverseNavigationProperty.Count > 0,
                ReverseNavigationProperty = table.ReverseNavigationProperty
                                            .OrderBy(x => x.Definition)
                                            .Select(x => new PocoReverseNavigationPropertyModel
                {
                    ReverseNavHasComment = Settings.IncludeComments != CommentsStyle.None && !string.IsNullOrEmpty(x.Comments),
                    ReverseNavComment    = Settings.IncludeComments != CommentsStyle.None ? x.Comments : string.Empty,
                    AdditionalReverseNavigationsDataAnnotations = Settings.AdditionalReverseNavigationsDataAnnotations,
                    AdditionalDataAnnotations = x.AdditionalDataAnnotations,
                    Definition = x.Definition
                })
                                            .ToList(),

                HasForeignKey                  = foreignKeys.Any(),
                ForeignKeys                    = foreignKeys,
                MappingConfiguration           = table.MappingConfiguration,
                ConfigurationClassesArePartial = Settings.ConfigurationClassesArePartial(),
                Indexes    = indexes,
                HasIndexes = hasIndexes
            };

            var co = new CodeOutput(table.NameHumanCaseWithSuffix() + Settings.ConfigurationClassName + Settings.FileExtension, null, GlobalUsings);

            co.AddUsings(Template.PocoConfigurationUsings(data));
            co.AddCode(Template.Transform(Template.PocoConfiguration(), data));
            return(co);
        }
Exemplo n.º 2
0
        public override List <string> PocoConfigurationUsings(PocoConfigurationModel data)
        {
            var usings = new List <string>
            {
                "Microsoft.EntityFrameworkCore",
                "Microsoft.EntityFrameworkCore.Metadata.Builders"
            };

            if (Settings.IncludeCodeGeneratedAttribute)
            {
                usings.Add("System.CodeDom.Compiler");
            }

            return(usings);
        }
Exemplo n.º 3
0
        public override List <string> PocoConfigurationUsings(PocoConfigurationModel data)
        {
            var usings = new List <string>
            {
                "System",
                "System.Data.Entity.ModelConfiguration",
                "System.ComponentModel.DataAnnotations.Schema"
            };

            if (Settings.IncludeCodeGeneratedAttribute)
            {
                usings.Add("System.CodeDom.Compiler");
            }

            return(usings);
        }
 public override List <string> PocoConfigurationUsings(PocoConfigurationModel data)
 {
     return(CacheList(TemplateFileBasedConstants.Text.PocoConfigurationUsings));
 }
Exemplo n.º 5
0
 public abstract List <string> PocoConfigurationUsings(PocoConfigurationModel data);
Exemplo n.º 6
0
        public override List <string> PocoConfigurationUsings(PocoConfigurationModel data)
        {
            var file = Path.Combine(Settings.TemplateFolder, "PocoConfigurationUsings.txt");

            return(File.ReadLines(file).ToList());
        }
Exemplo n.º 7
0
        public CodeOutput GeneratePocoConfiguration(Table table)
        {
            var filename = table.NameHumanCaseWithSuffix() + Settings.ConfigurationClassName + Settings.FileExtension;

            if (!CanWritePocoConfiguration())
            {
                FileManagementService.DeleteFile(filename);
                return(null);
            }

            var columns = table.Columns
                          .Where(x => !x.Hidden && !string.IsNullOrEmpty(x.Config))
                          .OrderBy(x => x.Ordinal)
                          .ToList();

            var isEfCore3Plus = Settings.IsEfCore3Plus();

            var foreignKeys = columns.SelectMany(x => x.ConfigFk).OrderBy(o => o).ToList();
            var primaryKey  = _generator.PrimaryKeyModelBuilder(table);

            var indexes    = _generator.IndexModelBuilder(table);
            var hasIndexes = indexes != null && indexes.Any();

            var data = new PocoConfigurationModel
            {
                UseHasNoKey               = isEfCore3Plus && table.IsView && !table.HasPrimaryKey,
                Name                      = table.DbName,
                ToTableOrView             = (isEfCore3Plus && table.IsView && !table.HasPrimaryKey) ? "ToView" : "ToTable",
                ConfigurationClassName    = table.NameHumanCaseWithSuffix() + Settings.ConfigurationClassName,
                NameHumanCaseWithSuffix   = table.NameHumanCaseWithSuffix(),
                Schema                    = table.Schema.DbName,
                PrimaryKeyNameHumanCase   = primaryKey ?? table.PrimaryKeyNameHumanCase(),
                HasSchema                 = !string.IsNullOrEmpty(table.Schema.DbName),
                ClassModifier             = Settings.ConfigurationClassesModifiers,
                ClassComment              = table.WriteComments(),
                Columns                   = columns.Select(x => x.Config).ToList(),
                HasReverseNavigation      = table.ReverseNavigationProperty.Count > 0,
                UsesDictionary            = table.UsesDictionary,
                ReverseNavigationProperty = table.ReverseNavigationProperty
                                            .OrderBy(x => x.Definition)
                                            .Select(x => new PocoReverseNavigationPropertyModel
                {
                    ReverseNavHasComment = Settings.IncludeComments != CommentsStyle.None && !string.IsNullOrEmpty(x.Comments),
                    ReverseNavComment    = Settings.IncludeComments != CommentsStyle.None ? x.Comments : string.Empty,
                    AdditionalReverseNavigationsDataAnnotations = Settings.AdditionalReverseNavigationsDataAnnotations,
                    AdditionalDataAnnotations = x.AdditionalDataAnnotations,
                    Definition = x.Definition
                })
                                            .ToList(),

                HasForeignKey                  = foreignKeys.Any(),
                ForeignKeys                    = foreignKeys,
                MappingConfiguration           = table.MappingConfiguration,
                ConfigurationClassesArePartial = Settings.ConfigurationClassesArePartial(),
                Indexes    = indexes,
                HasIndexes = hasIndexes
            };

            var co = new CodeOutput(table.DbName, filename, null, Settings.PocoConfigurationFolder, _globalUsings);

            co.AddUsings(_template.PocoConfigurationUsings(data));
            co.AddCode(Template.Transform(_template.PocoConfiguration(), data));
            return(co);
        }
 public override List <string> PocoConfigurationUsings(PocoConfigurationModel data)
 {
     return(CacheList("PocoConfigurationUsings.txt"));
 }