diff --git a/src/GUI/RevEng.Core.60/ReverseEngineerScaffolder.cs b/src/GUI/RevEng.Core.60/ReverseEngineerScaffolder.cs index 462b0abf0..16ef1f9da 100644 --- a/src/GUI/RevEng.Core.60/ReverseEngineerScaffolder.cs +++ b/src/GUI/RevEng.Core.60/ReverseEngineerScaffolder.cs @@ -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, @@ -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); @@ -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) diff --git a/src/GUI/RevEng.Shared/ReverseEngineerCommandOptions.cs b/src/GUI/RevEng.Shared/ReverseEngineerCommandOptions.cs index 68603b88d..11bf8fc10 100644 --- a/src/GUI/RevEng.Shared/ReverseEngineerCommandOptions.cs +++ b/src/GUI/RevEng.Shared/ReverseEngineerCommandOptions.cs @@ -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; } } } diff --git a/src/GUI/Shared/Handlers/ReverseEngineer/EfRevEngLauncher.cs b/src/GUI/Shared/Handlers/ReverseEngineer/EfRevEngLauncher.cs index ce8a8ebc9..16c13497e 100644 --- a/src/GUI/Shared/Handlers/ReverseEngineer/EfRevEngLauncher.cs +++ b/src/GUI/Shared/Handlers/ReverseEngineer/EfRevEngLauncher.cs @@ -115,6 +115,7 @@ public static async Task LaunchExternalRunnerAsync(Revers UseDateOnlyTimeOnly = options.UseDateOnlyTimeOnly, UseSchemaNamespaces = options.UseSchemaNamespaces, UseDecimalDataAnnotation = options.UseDecimalDataAnnotationForSprocResult, + RemoveValueGeneratedOnAdd = options.RemoveValueGeneratedOnAdd, }; var launcher = new EfRevEngLauncher(commandOptions, codeGenerationMode); diff --git a/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerOptions.cs b/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerOptions.cs index b39545625..fc8b7d3de 100644 --- a/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerOptions.cs +++ b/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerOptions.cs @@ -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; } } } diff --git a/src/GUI/lib/efreveng60.exe.zip b/src/GUI/lib/efreveng60.exe.zip index 1e8e9a57d..500458cda 100644 Binary files a/src/GUI/lib/efreveng60.exe.zip and b/src/GUI/lib/efreveng60.exe.zip differ diff --git a/src/GUI/lib/efreveng70.exe.zip b/src/GUI/lib/efreveng70.exe.zip index a08c47542..7fb24ef15 100644 Binary files a/src/GUI/lib/efreveng70.exe.zip and b/src/GUI/lib/efreveng70.exe.zip differ diff --git a/src/GUI/lib/efreveng80.exe.zip b/src/GUI/lib/efreveng80.exe.zip index 5150d2c9b..0bd5b0922 100644 Binary files a/src/GUI/lib/efreveng80.exe.zip and b/src/GUI/lib/efreveng80.exe.zip differ diff --git a/test/ScaffoldingTester/ConsoleApp/Models/ChinookContext.cs b/test/ScaffoldingTester/ConsoleApp/Models/ChinookContext.cs index 4d25f91ba..44a8bd124 100644 --- a/test/ScaffoldingTester/ConsoleApp/Models/ChinookContext.cs +++ b/test/ScaffoldingTester/ConsoleApp/Models/ChinookContext.cs @@ -10,9 +10,6 @@ namespace ConsoleApp.Models { public partial class ChinookContext : DbContext { - public ChinookContext() - {} - public ChinookContext(DbContextOptions options) : base(options) { @@ -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); } diff --git a/test/ScaffoldingTester/ConsoleApp/Models/ChinookContextProcedures.cs b/test/ScaffoldingTester/ConsoleApp/Models/ChinookContextProcedures.cs deleted file mode 100644 index 916f62bce..000000000 --- a/test/ScaffoldingTester/ConsoleApp/Models/ChinookContextProcedures.cs +++ /dev/null @@ -1,77 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -using ConsoleApp.Models; -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Data; -using System.Threading; -using System.Threading.Tasks; - -namespace ConsoleApp.Models -{ - public partial class ChinookContext - { - private IChinookContextProcedures _procedures; - - public virtual IChinookContextProcedures Procedures - { - get - { - if (_procedures is null) _procedures = new ChinookContextProcedures(this); - return _procedures; - } - set - { - _procedures = value; - } - } - - public IChinookContextProcedures GetProcedures() - { - return Procedures; - } - - protected void OnModelCreatingGeneratedProcedures(ModelBuilder modelBuilder) - { - modelBuilder.Entity().HasNoKey().ToView(null); - } - } - - public partial class ChinookContextProcedures : IChinookContextProcedures - { - private readonly ChinookContext _context; - - public ChinookContextProcedures(ChinookContext context) - { - _context = context; - } - - public virtual async Task> GetTitlesAsync(string Title, OutputParameter returnValue = null, CancellationToken cancellationToken = default) - { - var parameterreturnValue = new SqlParameter - { - ParameterName = "returnValue", - Direction = System.Data.ParameterDirection.Output, - SqlDbType = System.Data.SqlDbType.Int, - }; - - var sqlParameters = new [] - { - new SqlParameter - { - ParameterName = "Title", - Size = 200, - Value = Title ?? Convert.DBNull, - SqlDbType = System.Data.SqlDbType.NVarChar, - }, - parameterreturnValue, - }; - var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[GetTitles] @Title", sqlParameters, cancellationToken); - - returnValue?.SetValue(parameterreturnValue.Value); - - return _; - } - } -} diff --git a/test/ScaffoldingTester/ConsoleApp/Models/DbContextExtensions.cs b/test/ScaffoldingTester/ConsoleApp/Models/DbContextExtensions.cs deleted file mode 100644 index dcb542a85..000000000 --- a/test/ScaffoldingTester/ConsoleApp/Models/DbContextExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage; -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace ConsoleApp.Models -{ - public static class DbContextExtensions - { - public static async Task> SqlQueryAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class - { - if (parameters is null) - { - parameters = new object[] { }; - } - - if (typeof(T).GetProperties().Any()) - { - return await db.Set().FromSqlRaw(sql, parameters).ToListAsync(cancellationToken); - } - else - { - await db.Database.ExecuteSqlRawAsync(sql, parameters, cancellationToken); - return default; - } - } - } - - public class OutputParameter - { - private bool _valueSet = false; - - public TValue _value; - - public TValue Value - { - get - { - if (!_valueSet) - throw new InvalidOperationException("Value not set."); - - return _value; - } - } - - internal void SetValue(object value) - { - _valueSet = true; - - _value = null == value || Convert.IsDBNull(value) ? default(TValue) : (TValue)value; - } - } -} diff --git a/test/ScaffoldingTester/ConsoleApp/Models/GetTitlesResult.cs b/test/ScaffoldingTester/ConsoleApp/Models/GetTitlesResult.cs deleted file mode 100644 index 121e01947..000000000 --- a/test/ScaffoldingTester/ConsoleApp/Models/GetTitlesResult.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; - -namespace ConsoleApp.Models -{ - public partial class GetTitlesResult - { - public string AlbumTitle { get; set; } - } -} diff --git a/test/ScaffoldingTester/ConsoleApp/Models/IChinookContextProcedures.cs b/test/ScaffoldingTester/ConsoleApp/Models/IChinookContextProcedures.cs deleted file mode 100644 index e8051a8e1..000000000 --- a/test/ScaffoldingTester/ConsoleApp/Models/IChinookContextProcedures.cs +++ /dev/null @@ -1,17 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -using ConsoleApp.Models; -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Data; -using System.Threading; -using System.Threading.Tasks; - -namespace ConsoleApp.Models -{ - public partial interface IChinookContextProcedures - { - Task> GetTitlesAsync(string Title, OutputParameter returnValue = null, CancellationToken cancellationToken = default); - } -} diff --git a/test/ScaffoldingTester/ConsoleApp/efpt.config.json b/test/ScaffoldingTester/ConsoleApp/efpt.config.json index bd309dff6..79f0198af 100644 --- a/test/ScaffoldingTester/ConsoleApp/efpt.config.json +++ b/test/ScaffoldingTester/ConsoleApp/efpt.config.json @@ -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]", @@ -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 } \ No newline at end of file