From 66e1d54ed9c3c11a0abab3779bc8138fec59b6c3 Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Sun, 24 Nov 2024 10:46:59 +0100 Subject: [PATCH] Make ExcludeIndexes work with VS extension (#2649) fixes #2640 --- .../Contracts/ViewModels/ITableInformationViewModel.cs | 7 +++++-- src/GUI/Shared/ViewModels/ObjectTreeViewModel.cs | 3 ++- src/GUI/Shared/ViewModels/PickTablesViewModel.cs | 9 ++++++--- src/GUI/Shared/ViewModels/TableInformationViewModel.cs | 3 +++ .../ScaffoldingTester/ScaffoldingTester/efpt.config.json | 5 ++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/GUI/Shared/Contracts/ViewModels/ITableInformationViewModel.cs b/src/GUI/Shared/Contracts/ViewModels/ITableInformationViewModel.cs index 7b322a397..a8c6fcee7 100644 --- a/src/GUI/Shared/Contracts/ViewModels/ITableInformationViewModel.cs +++ b/src/GUI/Shared/Contracts/ViewModels/ITableInformationViewModel.cs @@ -1,4 +1,5 @@ -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; using RevEng.Common; namespace EFCorePowerTools.Contracts.ViewModels @@ -9,6 +10,8 @@ public interface ITableInformationViewModel : IObjectTreeEditableViewModel, IObj bool HasPrimaryKey { get; } + IEnumerable ExcludedIndexes { get; set; } + ObjectType ObjectType { get; set; } ObjectTypeIcon ObjectTypeIcon { get; } @@ -19,4 +22,4 @@ public interface ITableInformationViewModel : IObjectTreeEditableViewModel, IObj string ModelDisplayName { get; set; } } -} \ No newline at end of file +} diff --git a/src/GUI/Shared/ViewModels/ObjectTreeViewModel.cs b/src/GUI/Shared/ViewModels/ObjectTreeViewModel.cs index 196269159..6b6af48b7 100644 --- a/src/GUI/Shared/ViewModels/ObjectTreeViewModel.cs +++ b/src/GUI/Shared/ViewModels/ObjectTreeViewModel.cs @@ -81,7 +81,7 @@ public IEnumerable GetSelectedObjects() { return Objects .Where(c => c.IsSelected.Value) - .Select(m => new SerializationTableModel(m.ModelDisplayName, m.ObjectType, m.Columns.Where(c => !c.IsSelected.Value).Select(c => c.Name).ToList(), null)); + .Select(m => new SerializationTableModel(m.ModelDisplayName, m.ObjectType, m.Columns.Where(c => !c.IsSelected.Value).Select(c => c.Name).ToList(), m.ExcludedIndexes?.ToList() ?? null)); } public IEnumerable GetRenamedObjects() @@ -254,6 +254,7 @@ public void SelectObjects(IEnumerable objects) foreach (var obj in Objects) { var t = objects.FirstOrDefault(m => m.Name == obj.ModelDisplayName); + obj.ExcludedIndexes = t?.ExcludedIndexes ?? null; obj.SetSelectedCommand.Execute(t != null); if (obj.ObjectType.HasColumns() && obj.IsSelected.Value) { diff --git a/src/GUI/Shared/ViewModels/PickTablesViewModel.cs b/src/GUI/Shared/ViewModels/PickTablesViewModel.cs index 0a7ce704b..b3782eb8f 100644 --- a/src/GUI/Shared/ViewModels/PickTablesViewModel.cs +++ b/src/GUI/Shared/ViewModels/PickTablesViewModel.cs @@ -126,9 +126,12 @@ private void Ok_Executed() /// At least a single table, function or stored procedure must be selected. /// private bool Ok_CanExecute() - => ObjectTree.GetSelectedObjects().Any(c => c.ObjectType.HasColumns()) - || ObjectTree.GetSelectedObjects().Any(c => c.ObjectType == ObjectType.Procedure) - || ObjectTree.GetSelectedObjects().Any(c => c.ObjectType == ObjectType.ScalarFunction); + { + var selectedObjects = ObjectTree.GetSelectedObjects().ToList(); + return selectedObjects.Exists(c => c.ObjectType.HasColumns()) + || selectedObjects.Exists(c => c.ObjectType == ObjectType.Procedure) + || selectedObjects.Exists(c => c.ObjectType == ObjectType.ScalarFunction); + } private void Cancel_Executed() { diff --git a/src/GUI/Shared/ViewModels/TableInformationViewModel.cs b/src/GUI/Shared/ViewModels/TableInformationViewModel.cs index 0b1c50a93..5a6dc1dbd 100644 --- a/src/GUI/Shared/ViewModels/TableInformationViewModel.cs +++ b/src/GUI/Shared/ViewModels/TableInformationViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; @@ -37,6 +38,8 @@ public TableInformationViewModel(IMessenger messenger) Columns.CollectionChanged += Columns_CollectionChanged; } + public IEnumerable ExcludedIndexes { get; set; } + public string Schema { get => schema; diff --git a/test/ScaffoldingTester/ScaffoldingTester/efpt.config.json b/test/ScaffoldingTester/ScaffoldingTester/efpt.config.json index 4685bcc29..5cdd42537 100644 --- a/test/ScaffoldingTester/ScaffoldingTester/efpt.config.json +++ b/test/ScaffoldingTester/ScaffoldingTester/efpt.config.json @@ -15,6 +15,9 @@ "T4TemplatePath": null, "Tables": [ { + "ExcludedIndexes": [ + "PK_Categories" + ], "Name": "[dbo].[Categories]", "ObjectType": 0 }, @@ -164,6 +167,7 @@ "UseAsyncStoredProcedureCalls": true, "UseBoolPropertiesWithoutDefaultSql": true, "UseDatabaseNames": false, + "UseDatabaseNamesForRoutines": false, "UseDateOnlyTimeOnly": false, "UseDbContextSplitting": false, "UseDecimalDataAnnotationForSprocResult": true, @@ -178,7 +182,6 @@ "UseNoObjectFilter": false, "UseNodaTime": false, "UseNullableReferences": false, - "UsePascalNamesForStoredProceduresAndFunctions": false, "UsePrefixNavigationNaming": false, "UseSchemaFolders": false, "UseSchemaNamespaces": false,