Skip to content

Commit

Permalink
loresoft#543 Add generate option for data mapping classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Boussaer authored and Arnaud Boussaer committed Mar 22, 2024
1 parent ceaa6a5 commit 685a3ca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ private void GenerateQueryExtensions(EntityContext entityContext)

private void GenerateMappingClasses(EntityContext entityContext)
{
if (!Options.Data.Mapping.Generate)
return;

foreach (var entity in entityContext.Entities)
{
Options.Variables.Set(entity);
Expand Down
1 change: 1 addition & 0 deletions src/EntityFrameworkCore.Generator.Core/OptionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private static void MapMapping(MappingClassOptions option, MappingClass mapping)
{
MapClassBase(option, mapping);

option.Generate = mapping.Generate;
option.Temporal = mapping.Temporal;
option.RowVersion = mapping.RowVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ public MappingClassOptions(VariableDictionary variables, string prefix)
Namespace = "{Project.Namespace}.Data.Mapping";
Directory = @"{Project.Directory}\Data\Mapping";
Name = "{Entity.Name}Map";

Generate = true;
}

/// <summary>
/// Gets or sets a value indicating whether this option is generated.
/// </summary>
/// <value>
/// <c>true</c> to generate; otherwise, <c>false</c>.
/// </value>
public bool Generate { get; set; }

/// <summary>
/// Gets or sets if temporal table mapping is enabled. Default true
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public MappingClass()
Name = "{Entity.Name}Map";
}

/// <summary>
/// Gets or sets a value indicating whether this option is generated.
/// </summary>
/// <value>
/// <c>true</c> to generate; otherwise, <c>false</c>.
/// </value>
[DefaultValue(true)]
public bool Generate { get; set; } = true;

/// <summary>
/// Gets or sets if temporal table mapping is enabled. Default true
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data:
properties:
- ^{Table.Name}(?=Id|Name)
mapping:
generate: true
namespace: '{Project.Namespace}.Data.Mapping'
directory: '{Project.Directory}\Data\Mapping'
document: false
Expand Down

0 comments on commit 685a3ca

Please sign in to comment.