From e11e5376eea36e05b6b55c48b080f3109eefc844 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 5 Jan 2020 13:06:30 +0100 Subject: [PATCH 1/5] Enum mappings in entity generation. Dicionary of schema.table.property to namespace.enum that will get replaced in generation. --- docs/ef/entity.md | 6 ++ .../Metadata/Generation/Property.cs | 1 + .../ModelGenerator.cs | 3 + .../Options/EntityClassOptions.cs | 5 + .../Templates/EntityClassTemplate.cs | 3 + .../ModelGeneratorTests.cs | 92 +++++++++++++++++++ 6 files changed, 110 insertions(+) diff --git a/docs/ef/entity.md b/docs/ef/entity.md index 55a15bec..0b85b1a0 100644 --- a/docs/ef/entity.md +++ b/docs/ef/entity.md @@ -58,6 +58,8 @@ data: entityNaming: Singular relationshipNaming: Plural prefixWithSchemaName: false + enumMappings: + dbo.Table.Property: My.Namespace.Enum ``` ### namespace @@ -88,6 +90,10 @@ Configuration on how to generate relationship property names. Default: `Plural` Control if class names should be generated with schema name prefixed eg. dbo.MyTable = DboMyTable. Default: `false` +### enumMappings + +Dictionary for enum mappings instead of eg. `int` to replace a property use `schema.table.property: namespace.enum` + ### document Include XML documentation for the generated class. Default: `false` diff --git a/src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Property.cs b/src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Property.cs index d8df0118..db3f47f6 100644 --- a/src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Property.cs +++ b/src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Property.cs @@ -21,6 +21,7 @@ public class Property : ModelBase public DbType DataType { get; set; } public Type SystemType { get; set; } + public string EnumTypeName { get; set; } public bool? IsNullable { get; set; } diff --git a/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs b/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs index cf1efce7..93fa7858 100644 --- a/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs +++ b/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs @@ -183,7 +183,10 @@ private void CreateProperties(Entity entity, IEnumerable columns property.StoreType = mapping.StoreType; property.NativeType = mapping.StoreTypeNameBase; property.DataType = mapping.DbType ?? DbType.AnsiString; + property.SystemType = mapping.ClrType; + var fullName = $"{column.Table.Schema}.{column.Table.Name}.{column.Name}"; + property.EnumTypeName = _options.Data.Entity.EnumMappings.GetValueOrDefault(fullName); property.Size = mapping.Size; property.IsProcessed = true; diff --git a/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs b/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs index 540155ee..80ec5dd7 100644 --- a/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs +++ b/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; namespace EntityFrameworkCore.Generator.Options @@ -21,6 +22,7 @@ public EntityClassOptions(VariableDictionary variables, string prefix) RelationshipNaming = RelationshipNaming.Plural; EntityNaming = EntityNaming.Singular; PrefixWithSchemaName = false; + EnumMappings = new Dictionary(); } /// @@ -58,5 +60,8 @@ public string BaseClass /// [DefaultValue(false)] public bool PrefixWithSchemaName { get; set; } + + + public Dictionary EnumMappings { get; set; } } } \ No newline at end of file diff --git a/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs b/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs index 80fb8dfe..91272a8a 100644 --- a/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs +++ b/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs @@ -111,6 +111,9 @@ private void GenerateProperties() foreach (var property in _entity.Properties) { var propertyType = property.SystemType.ToNullableType(property.IsNullable == true); + if (property.EnumTypeName != null) + propertyType = property.EnumTypeName.ToNullableType(property.IsNullable == true); + var propertyName = property.PropertyName.ToSafeName(); if (Options.Data.Entity.Document) diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/ModelGeneratorTests.cs b/test/EntityFrameworkCore.Generator.Core.Tests/ModelGeneratorTests.cs index 62dd2d09..1f972b9f 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/ModelGeneratorTests.cs +++ b/test/EntityFrameworkCore.Generator.Core.Tests/ModelGeneratorTests.cs @@ -457,6 +457,98 @@ public void GenerateWithPrefixedSchemaName() } + [Fact] + public void GenerateWithEnumMappings() + { + + var generatorOptions = new GeneratorOptions(); + generatorOptions.Data.Entity.PrefixWithSchemaName = true; + generatorOptions.Data.Entity.EnumMappings = new Dictionary { + {"tst.TestTable.TestEnumType", "My.NameSpace.MyTestEnum" } + }; + var databaseModel = new DatabaseModel + { + DatabaseName = "TestDatabase", + DefaultSchema = "dbo" + }; + var testTableDbo = new DatabaseTable + { + Database = databaseModel, + Name = "TestTable", + Schema = "dbo" + }; + var testTableTst = new DatabaseTable + { + Database = databaseModel, + Name = "TestTable", + Schema = "tst" + }; + databaseModel.Tables.Add(testTableDbo); + databaseModel.Tables.Add(testTableTst); + + var identifierColumnDbo = new DatabaseColumn + { + Table = testTableDbo, + Name = "Id", + IsNullable = false, + StoreType = "int" + }; + var identifierColumnTst = new DatabaseColumn + { + Table = testTableTst, + Name = "Id", + IsNullable = false, + StoreType = "int" + }; + testTableDbo.Columns.Add(identifierColumnDbo); + testTableTst.Columns.Add(identifierColumnTst); + + var nameColumnDbo = new DatabaseColumn + { + Table = testTableDbo, + Name = "Name", + IsNullable = true, + StoreType = "varchar(50)" + }; + var enumColumnTst = new DatabaseColumn + { + Table = testTableTst, + Name = "TestEnumType", + IsNullable = true, + StoreType = "int" + }; + testTableDbo.Columns.Add(nameColumnDbo); + testTableTst.Columns.Add(enumColumnTst); + + var generator = new ModelGenerator(NullLoggerFactory.Instance); + + var typeMappingSource = CreateTypeMappingSource(); + + var result = generator.Generate(generatorOptions, databaseModel, typeMappingSource); + + result.ContextClass.Should().Be("TestDatabaseContext"); + result.ContextNamespace.Should().Be("TestDatabase.Data"); + result.Entities.Count.Should().Be(2); + + var firstEntity = result.Entities[0]; + firstEntity.TableName.Should().Be("TestTable"); + firstEntity.TableSchema.Should().Be("dbo"); + firstEntity.EntityClass.Should().Be("DboTestTable"); + firstEntity.EntityNamespace.Should().Be("TestDatabase.Data.Entities"); + firstEntity.MappingClass.Should().Be("DboTestTableMap"); + firstEntity.MappingNamespace.Should().Be("TestDatabase.Data.Mapping"); + + var secondEntity = result.Entities[1]; + secondEntity.TableName.Should().Be("TestTable"); + secondEntity.TableSchema.Should().Be("tst"); + secondEntity.EntityClass.Should().Be("TstTestTable"); + secondEntity.EntityNamespace.Should().Be("TestDatabase.Data.Entities"); + secondEntity.MappingClass.Should().Be("TstTestTableMap"); + secondEntity.MappingNamespace.Should().Be("TestDatabase.Data.Mapping"); + secondEntity.Properties.First(x => x.PropertyName == "TestEnumType").EnumTypeName.Should().Be("My.NameSpace.MyTestEnum"); + + } + private static SqlServerTypeMappingSource CreateTypeMappingSource() { #pragma warning disable EF1001 // Internal EF Core API usage. From 5ee9998e762fa80807139ad4c3db43932f70ff42 Mon Sep 17 00:00:00 2001 From: adolfodiazm Date: Tue, 9 Jun 2020 11:13:59 -0400 Subject: [PATCH 2/5] one to many relationship improvement --- src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs b/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs index ad58371d..bc711425 100644 --- a/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs +++ b/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs @@ -227,8 +227,14 @@ private void CreateRelationships(EntityContext entityContext, Entity entity, Dat private void CreateRelationship(EntityContext entityContext, Entity foreignEntity, DatabaseForeignKey tableKeySchema) { + _options.Variables.Set(VariableConstants.TableSchema, ToLegalName(tableKeySchema.PrincipalTable.Schema)); + _options.Variables.Set(VariableConstants.TableName, ToLegalName(tableKeySchema.PrincipalTable.Name)); + Entity primaryEntity = GetEntity(entityContext, tableKeySchema.PrincipalTable, false, false); + _options.Variables.Set(VariableConstants.TableSchema, ToLegalName(tableKeySchema.Table.Schema)); + _options.Variables.Set(VariableConstants.TableName, ToLegalName(tableKeySchema.Table.Name)); + string primaryName = primaryEntity.EntityClass; string foreignName = foreignEntity.EntityClass; From 7528a77ba0bebdf43763c32eed8b602c7babffa6 Mon Sep 17 00:00:00 2001 From: adolfodiazm Date: Thu, 11 Jun 2020 13:57:27 -0400 Subject: [PATCH 3/5] arreglo foreign key, ahora obtiene nombre de bd --- .../ModelGenerator.cs | 8 +- .../generation.yml | 122 ++++++++++++++++++ .../generation.yml | 115 +++++++++++++++++ 3 files changed, 241 insertions(+), 4 deletions(-) create mode 100644 src/EntityFrameworkCore.Generator.Core/generation.yml create mode 100644 src/EntityFrameworkCore.Generator/generation.yml diff --git a/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs b/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs index 0d2ec613..76fb8b6b 100644 --- a/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs +++ b/src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs @@ -239,7 +239,7 @@ private void CreateRelationship(EntityContext entityContext, Entity foreignEntit _options.Variables.Set(VariableConstants.TableName, ToLegalName(tableKeySchema.Table.Name)); string primaryName = primaryEntity.EntityClass; - string foreignName = foreignEntity.EntityClass; + string foreignName = tableKeySchema.Name.ToLower(); string relationshipName = tableKeySchema.Name; relationshipName = _namer.UniqueRelationshipName(relationshipName); @@ -275,9 +275,9 @@ private void CreateRelationship(EntityContext entityContext, Entity foreignEntit foreignRelationship.Entity = foreignEntity; foreignRelationship.Properties = new PropertyCollection(foreignMembers); - string prefix = GetMemberPrefix(foreignRelationship, primaryName, foreignName); + //string prefix = GetMemberPrefix(foreignRelationship, primaryName, foreignName); - string foreignPropertyName = ToPropertyName(foreignEntity.EntityClass, prefix + primaryName); + string foreignPropertyName = ToPropertyName(foreignEntity.EntityClass, /*prefix +*/ foreignName); foreignPropertyName = _namer.UniqueName(foreignEntity.EntityClass, foreignPropertyName); foreignRelationship.PropertyName = foreignPropertyName; @@ -306,7 +306,7 @@ private void CreateRelationship(EntityContext entityContext, Entity foreignEntit else primaryRelationship.Cardinality = Cardinality.Many; - string primaryPropertyName = prefix + foreignName; + string primaryPropertyName = /*prefix +*/ foreignName; if (!isOneToOne) primaryPropertyName = RelationshipName(primaryPropertyName); diff --git a/src/EntityFrameworkCore.Generator.Core/generation.yml b/src/EntityFrameworkCore.Generator.Core/generation.yml new file mode 100644 index 00000000..21f24e2c --- /dev/null +++ b/src/EntityFrameworkCore.Generator.Core/generation.yml @@ -0,0 +1,122 @@ +--- +#---------------------------------# +# https://efg.loresoft.com/en/latest/ +# project section - Used for shared variables through out the configuration file +#---------------------------------# +project: + # the root namespace for the project + namespace: 'api' + # the root directory for the project + directory: ./ + +#---------------------------------# +# data section - Used for configuring database connections +#---------------------------------# +database: + # the connection string to the database + connectionString: 'Server=hulk;Initial Catalog=SISTEMAS;Integrated Security=True;MultipleActiveResultSets=True' + # the database provider name. Default: SqlServer + provider: SqlServer + + # config name to read the connection string from the user secrets file + connectionName: 'ConnectionStrings:Generator' + # the user secret identifier, can be shared with .net core project + userSecretsId: '984ef0cf-2b22-4fd1-876d-e01489da4c1f' + + # tables to include or empty to include all + tables: + - dbo.usuario + - dbo.accion + - dbo.peticion + - dbo.accion_peticion + - dbo.accion_usuario + - dbo.rol_usuario_aplicacion + - dbo.rol + - dbo.aplicacion + # schemas to include or empty to include all + schemas: + # table naming hint for how existing tables are named. Default: Singular + tableNaming: Singular + +#---------------------------------# +# data section - controls the generated files for Entity Framework +#---------------------------------# +data: + # data context file configuration + context: + name: 'ContextoDb' # the data context class name + baseClass: DbContext # the data context base class name + namespace: '{Project.Namespace}.Data' # the data context namespace + directory: '{Project.Directory}/Data' # the data context output directory + + # how to generate names for the DbSet properties on the data context. Default: Plural + propertyNaming: Suffix + #include XML documentation + document: false + + # entity class file configuration + entity: + namespace: '{Project.Namespace}.Data.Entities' # the entity class namespace + directory: '{Project.Directory}/Data/Entities' # the entity class output directory + + # how to generate entity class names from the table name. Default: Singular + entityNaming: Preserve + relationshipNaming: Suffix + name: '{Table.Schema}{Table.Name}Entity' + #baseClass: BaseEntity + + # how to generate relationship collections names for the entity. Default: Plural + #relationshipNaming: Suffix + #include XML documentation + document: false + + # Generate class names with prefixed schema name eg. dbo.MyTable = DboMyTable + # prefixWithSchemaName: true + enumMappings: + dbo.usuario.activo: api.Data.CustomEnums.YesNoEnum + mapping: + namespace: '{Project.Namespace}.Data.Mapping' # the mapping class namespace + directory: '{Project.Directory}/Data/Mapping' # the mapping class output directory + #include XML documentation + document: false +#---------------------------------# +# model section - controls the optional view model generation +#---------------------------------# +model: + # shared options between read, create and update models + shared: + namespace: '{Project.Namespace}.Data.Models' # the model class namespace + directory: '{Project.Directory}/Data/Models' # the mapping class output directory + # regular expression of entities and properties to exclude in all models + exclude: + # list of regular expressions of entity names + entities: + + # list of regular expressions of property names, source is Entity.Property + properties: + # update view model class configuration + update: + generate: true # generate update model class files + name: '{Table.Schema}_{Table.Name}Model' # the update model class name + #baseClass: EntityUpdateModel # the update model base class + namespace: '{Project.Namespace}.Data.Models' + directory: '{Project.Directory}/Data/Models' + exclude: + entities: [] + properties: [] + + # AutoMapper class configuration + mapper: + generate: true + name: '{Table.Schema}_{Table.Name}Profile' + baseClass: Profile + namespace: '{Project.Namespace}.Data.AutoMapper' + directory: '{Project.Directory}/Data/AutoMapper' + + # FluentValidation class configuration + validator: + generate: true + name: '{Model.Name}Validator' + baseClass: 'AbstractValidator<{Model.Name}>' + namespace: '{Project.Namespace}.Data.ModelValidation' + directory: '{Project.Directory}/Data/ModelValidation' diff --git a/src/EntityFrameworkCore.Generator/generation.yml b/src/EntityFrameworkCore.Generator/generation.yml new file mode 100644 index 00000000..a86b65a5 --- /dev/null +++ b/src/EntityFrameworkCore.Generator/generation.yml @@ -0,0 +1,115 @@ +--- +#---------------------------------# +# https://efg.loresoft.com/en/latest/ +# project section - Used for shared variables through out the configuration file +#---------------------------------# +project: + # the root namespace for the project + namespace: 'api' + # the root directory for the project + directory: ./ + +#---------------------------------# +# data section - Used for configuring database connections +#---------------------------------# +database: + # the connection string to the database + connectionString: 'Server=hulk;Initial Catalog=SISTEMAS;Integrated Security=True;MultipleActiveResultSets=True' + # the database provider name. Default: SqlServer + provider: SqlServer + + # config name to read the connection string from the user secrets file + connectionName: 'ConnectionStrings:Generator' + # the user secret identifier, can be shared with .net core project + userSecretsId: '984ef0cf-2b22-4fd1-876d-e01489da4c1f' + + # tables to include or empty to include all + tables: + - dbo.LOG_SOP10200 + # schemas to include or empty to include all + schemas: + # table naming hint for how existing tables are named. Default: Singular + tableNaming: Singular + +#---------------------------------# +# data section - controls the generated files for Entity Framework +#---------------------------------# +data: + # data context file configuration + context: + name: 'ContextoDb' # the data context class name + baseClass: DbContext # the data context base class name + namespace: '{Project.Namespace}.Data' # the data context namespace + directory: '{Project.Directory}/Data' # the data context output directory + + # how to generate names for the DbSet properties on the data context. Default: Plural + propertyNaming: Suffix + #include XML documentation + document: false + + # entity class file configuration + entity: + namespace: '{Project.Namespace}.Data.Entities' # the entity class namespace + directory: '{Project.Directory}/Data/Entities' # the entity class output directory + + # how to generate entity class names from the table name. Default: Singular + entityNaming: Preserve + relationshipNaming: Suffix + name: '{Table.Schema}{Table.Name}Entity' + #baseClass: BaseEntity + + # how to generate relationship collections names for the entity. Default: Plural + #relationshipNaming: Suffix + #include XML documentation + document: false + + # Generate class names with prefixed schema name eg. dbo.MyTable = DboMyTable + # prefixWithSchemaName: true + enumMappings: + dbo.usuario.activo: api.Data.CustomEnums.YesNoEnum + mapping: + namespace: '{Project.Namespace}.Data.Mapping' # the mapping class namespace + directory: '{Project.Directory}/Data/Mapping' # the mapping class output directory + #include XML documentation + document: false +#---------------------------------# +# model section - controls the optional view model generation +#---------------------------------# +model: + # shared options between read, create and update models + shared: + namespace: '{Project.Namespace}.Data.Models' # the model class namespace + directory: '{Project.Directory}/Data/Models' # the mapping class output directory + # regular expression of entities and properties to exclude in all models + exclude: + # list of regular expressions of entity names + entities: + + # list of regular expressions of property names, source is Entity.Property + properties: + # update view model class configuration + update: + generate: true # generate update model class files + name: '{Table.Schema}_{Table.Name}Model' # the update model class name + #baseClass: EntityUpdateModel # the update model base class + namespace: '{Project.Namespace}.Data.Models' + directory: '{Project.Directory}/Data/Models' + exclude: + entities: [] + properties: [] + + # AutoMapper class configuration + mapper: + generate: true + name: '{Table.Schema}_{Table.Name}Profile' + baseClass: Profile + namespace: '{Project.Namespace}.Data.AutoMapper' + directory: '{Project.Directory}/Data/AutoMapper' + + # FluentValidation class configuration + validator: + generate: true + name: '{Model.Name}Validator' + baseClass: 'AbstractValidator<{Model.Name}>' + namespace: '{Project.Namespace}.Data.ModelValidation' + directory: '{Project.Directory}/Data/ModelValidation' From 656f4145d4a43f08ee671cf322c9f22d5d030a63 Mon Sep 17 00:00:00 2001 From: adolfodiazm Date: Tue, 16 Jun 2020 11:34:32 -0400 Subject: [PATCH 4/5] arreglo enums en model --- .../Templates/ModelClassTemplate.cs | 3 + .../generation.yml | 122 ------------------ 2 files changed, 3 insertions(+), 122 deletions(-) delete mode 100644 src/EntityFrameworkCore.Generator.Core/generation.yml diff --git a/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs b/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs index eb772d26..f8ef001a 100644 --- a/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs +++ b/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs @@ -73,6 +73,9 @@ private void GenerateProperties() foreach (var property in _model.Properties) { var propertyType = property.SystemType.ToNullableType(property.IsNullable == true); + if (property.EnumTypeName != null) + propertyType = property.EnumTypeName.ToNullableType(property.IsNullable == true); + var propertyName = property.PropertyName.ToSafeName(); if (ShouldDocument()) diff --git a/src/EntityFrameworkCore.Generator.Core/generation.yml b/src/EntityFrameworkCore.Generator.Core/generation.yml deleted file mode 100644 index 21f24e2c..00000000 --- a/src/EntityFrameworkCore.Generator.Core/generation.yml +++ /dev/null @@ -1,122 +0,0 @@ ---- -#---------------------------------# -# https://efg.loresoft.com/en/latest/ -# project section - Used for shared variables through out the configuration file -#---------------------------------# -project: - # the root namespace for the project - namespace: 'api' - # the root directory for the project - directory: ./ - -#---------------------------------# -# data section - Used for configuring database connections -#---------------------------------# -database: - # the connection string to the database - connectionString: 'Server=hulk;Initial Catalog=SISTEMAS;Integrated Security=True;MultipleActiveResultSets=True' - # the database provider name. Default: SqlServer - provider: SqlServer - - # config name to read the connection string from the user secrets file - connectionName: 'ConnectionStrings:Generator' - # the user secret identifier, can be shared with .net core project - userSecretsId: '984ef0cf-2b22-4fd1-876d-e01489da4c1f' - - # tables to include or empty to include all - tables: - - dbo.usuario - - dbo.accion - - dbo.peticion - - dbo.accion_peticion - - dbo.accion_usuario - - dbo.rol_usuario_aplicacion - - dbo.rol - - dbo.aplicacion - # schemas to include or empty to include all - schemas: - # table naming hint for how existing tables are named. Default: Singular - tableNaming: Singular - -#---------------------------------# -# data section - controls the generated files for Entity Framework -#---------------------------------# -data: - # data context file configuration - context: - name: 'ContextoDb' # the data context class name - baseClass: DbContext # the data context base class name - namespace: '{Project.Namespace}.Data' # the data context namespace - directory: '{Project.Directory}/Data' # the data context output directory - - # how to generate names for the DbSet properties on the data context. Default: Plural - propertyNaming: Suffix - #include XML documentation - document: false - - # entity class file configuration - entity: - namespace: '{Project.Namespace}.Data.Entities' # the entity class namespace - directory: '{Project.Directory}/Data/Entities' # the entity class output directory - - # how to generate entity class names from the table name. Default: Singular - entityNaming: Preserve - relationshipNaming: Suffix - name: '{Table.Schema}{Table.Name}Entity' - #baseClass: BaseEntity - - # how to generate relationship collections names for the entity. Default: Plural - #relationshipNaming: Suffix - #include XML documentation - document: false - - # Generate class names with prefixed schema name eg. dbo.MyTable = DboMyTable - # prefixWithSchemaName: true - enumMappings: - dbo.usuario.activo: api.Data.CustomEnums.YesNoEnum - mapping: - namespace: '{Project.Namespace}.Data.Mapping' # the mapping class namespace - directory: '{Project.Directory}/Data/Mapping' # the mapping class output directory - #include XML documentation - document: false -#---------------------------------# -# model section - controls the optional view model generation -#---------------------------------# -model: - # shared options between read, create and update models - shared: - namespace: '{Project.Namespace}.Data.Models' # the model class namespace - directory: '{Project.Directory}/Data/Models' # the mapping class output directory - # regular expression of entities and properties to exclude in all models - exclude: - # list of regular expressions of entity names - entities: - - # list of regular expressions of property names, source is Entity.Property - properties: - # update view model class configuration - update: - generate: true # generate update model class files - name: '{Table.Schema}_{Table.Name}Model' # the update model class name - #baseClass: EntityUpdateModel # the update model base class - namespace: '{Project.Namespace}.Data.Models' - directory: '{Project.Directory}/Data/Models' - exclude: - entities: [] - properties: [] - - # AutoMapper class configuration - mapper: - generate: true - name: '{Table.Schema}_{Table.Name}Profile' - baseClass: Profile - namespace: '{Project.Namespace}.Data.AutoMapper' - directory: '{Project.Directory}/Data/AutoMapper' - - # FluentValidation class configuration - validator: - generate: true - name: '{Model.Name}Validator' - baseClass: 'AbstractValidator<{Model.Name}>' - namespace: '{Project.Namespace}.Data.ModelValidation' - directory: '{Project.Directory}/Data/ModelValidation' From 080fdab67037b1e695ef760a2d499c7bc8f15101 Mon Sep 17 00:00:00 2001 From: adolfodiazm Date: Thu, 25 Jun 2020 21:26:31 -0400 Subject: [PATCH 5/5] arreglo enum? --- .../Templates/EntityClassTemplate.cs | 2 +- .../Templates/ModelClassTemplate.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs b/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs index 1c1505ba..ef793821 100644 --- a/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs +++ b/src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs @@ -117,7 +117,7 @@ private void GenerateProperties() { var propertyType = property.SystemType.ToNullableType(property.IsNullable == true); if (property.EnumTypeName != null) - propertyType = property.EnumTypeName.ToNullableType(property.IsNullable == true); + propertyType = property.EnumTypeName.ToNullableType(property.IsNullable == true) + (propertyType.Contains("?") ? "?" : ""); var propertyName = property.PropertyName.ToSafeName(); diff --git a/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs b/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs index f8ef001a..58724e69 100644 --- a/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs +++ b/src/EntityFrameworkCore.Generator.Core/Templates/ModelClassTemplate.cs @@ -74,7 +74,7 @@ private void GenerateProperties() { var propertyType = property.SystemType.ToNullableType(property.IsNullable == true); if (property.EnumTypeName != null) - propertyType = property.EnumTypeName.ToNullableType(property.IsNullable == true); + propertyType = property.EnumTypeName.ToNullableType(property.IsNullable == true) + (propertyType.Contains("?") ? "?" : ""); var propertyName = property.PropertyName.ToSafeName();