Skip to content

Commit

Permalink
Make ExcludeIndexes work with VS extension
Browse files Browse the repository at this point in the history
fixes #2640
  • Loading branch information
ErikEJ committed Nov 24, 2024
1 parent 1dbbde8 commit cb4ea2e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using RevEng.Common;

namespace EFCorePowerTools.Contracts.ViewModels
Expand All @@ -9,6 +10,8 @@ public interface ITableInformationViewModel : IObjectTreeEditableViewModel, IObj

bool HasPrimaryKey { get; }

IEnumerable<string> ExcludedIndexes { get; set; }

ObjectType ObjectType { get; set; }

ObjectTypeIcon ObjectTypeIcon { get; }
Expand All @@ -19,4 +22,4 @@ public interface ITableInformationViewModel : IObjectTreeEditableViewModel, IObj

string ModelDisplayName { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion src/GUI/Shared/ViewModels/ObjectTreeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public IEnumerable<SerializationTableModel> 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<Schema> GetRenamedObjects()
Expand Down Expand Up @@ -254,6 +254,7 @@ public void SelectObjects(IEnumerable<SerializationTableModel> 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)
{
Expand Down
9 changes: 6 additions & 3 deletions src/GUI/Shared/ViewModels/PickTablesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ private void Ok_Executed()
/// At least a single table, function or stored procedure must be selected.
/// </summary>
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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/GUI/Shared/ViewModels/TableInformationViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
Expand Down Expand Up @@ -37,6 +38,8 @@ public TableInformationViewModel(IMessenger messenger)
Columns.CollectionChanged += Columns_CollectionChanged;
}

public IEnumerable<string> ExcludedIndexes { get; set; }

public string Schema
{
get => schema;
Expand Down
5 changes: 4 additions & 1 deletion test/ScaffoldingTester/ScaffoldingTester/efpt.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"T4TemplatePath": null,
"Tables": [
{
"ExcludedIndexes": [
"PK_Categories"
],
"Name": "[dbo].[Categories]",
"ObjectType": 0
},
Expand Down Expand Up @@ -164,6 +167,7 @@
"UseAsyncStoredProcedureCalls": true,
"UseBoolPropertiesWithoutDefaultSql": true,
"UseDatabaseNames": false,
"UseDatabaseNamesForRoutines": false,
"UseDateOnlyTimeOnly": false,
"UseDbContextSplitting": false,
"UseDecimalDataAnnotationForSprocResult": true,
Expand All @@ -178,7 +182,6 @@
"UseNoObjectFilter": false,
"UseNodaTime": false,
"UseNullableReferences": false,
"UsePascalNamesForStoredProceduresAndFunctions": false,
"UsePrefixNavigationNaming": false,
"UseSchemaFolders": false,
"UseSchemaNamespaces": false,
Expand Down

0 comments on commit cb4ea2e

Please sign in to comment.