Skip to content

Commit

Permalink
Add ability to remove ValueGeneratedOnAdd (#2055)
Browse files Browse the repository at this point in the history
fxies #2054
  • Loading branch information
ErikEJ authored Dec 19, 2023
1 parent 355d91f commit 28c94f4
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 187 deletions.
20 changes: 18 additions & 2 deletions src/GUI/RevEng.Core.60/ReverseEngineerScaffolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public SavedModelFiles GenerateDbContext(
options.SelectedToBeGenerated == 1, // DbContext only
options.SelectedToBeGenerated == 2, // Entities only
options.UseSchemaFolders,
options.UseSchemaNamespaces);
options.UseSchemaNamespaces,
options.RemoveValueGeneratedOnAdd);

filePaths = Save(
scaffoldedModel,
Expand Down Expand Up @@ -455,7 +456,8 @@ private ScaffoldedModel ScaffoldModel(
bool dbContextOnly,
bool entitiesOnly,
bool useSchemaFolders,
bool useSchemaNamespaces)
bool useSchemaNamespaces,
bool removeValueGeneratedOnAdd)
{
var databaseModel = databaseModelFactory.Create(connectionString, databaseOptions);

Expand Down Expand Up @@ -485,6 +487,20 @@ private ScaffoldedModel ScaffoldModel(
}
}

if (removeValueGeneratedOnAdd)
{
foreach (var table in databaseModel.Tables)
{
foreach (var column in table.Columns.ToList())
{
if (column.ValueGenerated == ValueGenerated.OnAdd)
{
column.ValueGenerated = null;
}
}
}
}

var model = factory.Create(databaseModel, modelOptions);

if (model == null)
Expand Down
1 change: 1 addition & 0 deletions src/GUI/RevEng.Shared/ReverseEngineerCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ public class ReverseEngineerCommandOptions
public bool UseDecimalDataAnnotation { get; set; }
public bool PreserveCasingWithRegex { get; set; }
public bool UseDateOnlyTimeOnly { get; set; }
public bool RemoveValueGeneratedOnAdd { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static async Task<ReverseEngineerResult> LaunchExternalRunnerAsync(Revers
UseDateOnlyTimeOnly = options.UseDateOnlyTimeOnly,
UseSchemaNamespaces = options.UseSchemaNamespaces,
UseDecimalDataAnnotation = options.UseDecimalDataAnnotationForSprocResult,
RemoveValueGeneratedOnAdd = options.RemoveValueGeneratedOnAdd,
};

var launcher = new EfRevEngLauncher(commandOptions, codeGenerationMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ public class ReverseEngineerOptions
public bool UseDateOnlyTimeOnly { get; set; }
public string T4TemplatePath { get; set; }
public bool UseDecimalDataAnnotationForSprocResult { get; set; } = true;
public bool RemoveValueGeneratedOnAdd { get; set; }
}
}
Binary file modified src/GUI/lib/efreveng60.exe.zip
Binary file not shown.
Binary file modified src/GUI/lib/efreveng70.exe.zip
Binary file not shown.
Binary file modified src/GUI/lib/efreveng80.exe.zip
Binary file not shown.
26 changes: 11 additions & 15 deletions test/ScaffoldingTester/ConsoleApp/Models/ChinookContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace ConsoleApp.Models
{
public partial class ChinookContext : DbContext
{
public ChinookContext()
{}

public ChinookContext(DbContextOptions<ChinookContext> options)
: base(options)
{
Expand All @@ -34,24 +31,23 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseSqlServer("Data Source=.\\SQLEXPRESS;Initial Catalog=Chinook;Integrated Security=True", x => x.UseNetTopologySuite());
optionsBuilder.UseSqlServer("Data Source=.\\SQLEXPRESS;Initial Catalog=Chinook;Integrated Security=True;Multiple Active Result Sets=True;Encrypt=True", x => x.UseNetTopologySuite());
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new Configurations.AlbumConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.ArtistConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.CustomerConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.EmployeeConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.GenreConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.InvoiceConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.InvoiceLineConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.MediaTypeConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.PlaylistConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.TrackConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.AlbumConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.ArtistConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.CustomerConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.EmployeeConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.GenreConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.InvoiceConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.InvoiceLineConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.MediaTypeConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.PlaylistConfiguration());
modelBuilder.ApplyConfiguration(new Configurations.TrackConfiguration());

OnModelCreatingGeneratedProcedures(modelBuilder);
OnModelCreatingPartial(modelBuilder);
}

Expand Down

This file was deleted.

59 changes: 0 additions & 59 deletions test/ScaffoldingTester/ConsoleApp/Models/DbContextExtensions.cs

This file was deleted.

12 changes: 0 additions & 12 deletions test/ScaffoldingTester/ConsoleApp/Models/GetTitlesResult.cs

This file was deleted.

This file was deleted.

12 changes: 7 additions & 5 deletions test/ScaffoldingTester/ConsoleApp/efpt.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
"ModelNamespace": null,
"OutputContextPath": null,
"OutputPath": "Models",
"PreserveCasingWithRegex": true,
"ProjectRootNamespace": "ConsoleApp",
"RemoveValueGeneratedOnAdd": false,
"Schemas": null,
"SelectedHandlebarsLanguage": 0,
"SelectedToBeGenerated": 0,
"T4TemplatePath": null,
"Tables": [
{
"Name": "[dbo].[Album]",
Expand Down Expand Up @@ -56,29 +59,28 @@
{
"Name": "[dbo].[Track]",
"ObjectType": 0
},
{
"Name": "[dbo].[GetTitles]",
"ObjectType": 1
}
],
"UiHint": "DG-PF2WPPLD\\SQLEXPRESS.Chinook",
"UncountableWords": null,
"UseBoolPropertiesWithoutDefaultSql": false,
"UseDatabaseNames": false,
"UseDateOnlyTimeOnly": false,
"UseDbContextSplitting": true,
"UseDecimalDataAnnotationForSprocResult": true,
"UseFluentApiOnly": true,
"UseHandleBars": false,
"UseHierarchyId": false,
"UseInflector": true,
"UseLegacyPluralizer": false,
"UseManyToManyEntity": false,
"UseNoConstructor": false,
"UseNoDefaultConstructor": true,
"UseNoNavigations": false,
"UseNoObjectFilter": false,
"UseNodaTime": false,
"UseNullableReferences": false,
"UseSchemaFolders": false,
"UseSchemaNamespaces": false,
"UseSpatial": true,
"UseT4": false
}

0 comments on commit 28c94f4

Please sign in to comment.