Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable UI for keyless tables and views #263

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public interface IPickServerDatabaseViewModel : IViewModel

DatabaseConnectionModel SelectedDatabaseConnection { get; set; }
DatabaseDefinitionModel SelectedDatabaseDefinition { get; set; }

bool IncludeViews { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using Shared.Models;

public interface IPickServerDatabaseDialog : IDialog<(DatabaseConnectionModel Connection, DatabaseDefinitionModel Definition)>
public interface IPickServerDatabaseDialog : IDialog<(DatabaseConnectionModel Connection, DatabaseDefinitionModel Definition, bool IncludeViews)>
{
void PublishConnections(IEnumerable<DatabaseConnectionModel> connections);
void PublishDefinitions(IEnumerable<DatabaseDefinitionModel> definitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
</ComboBox.ItemTemplate>
</ComboBox>

<StackPanel
Grid.Row="3"
Orientation="Horizontal"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<CheckBox x:Name="IncludeViews" IsChecked="{Binding IncludeViews}" >Include views (requires EF Core 3.0)</CheckBox>
</StackPanel>

<StackPanel Grid.Row="3"
Orientation="Horizontal"
HorizontalAlignment="Right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public partial class PickServerDatabaseDialog : IPickServerDatabaseDialog
{
private readonly Func<(DatabaseConnectionModel Connection, DatabaseDefinitionModel Definition)> _getDialogResult;
private readonly Func<(DatabaseConnectionModel Connection, DatabaseDefinitionModel Definition, bool IncludeViews)> _getDialogResult;
private readonly Action<IEnumerable<DatabaseConnectionModel>> _addConnections;
private readonly Action<IEnumerable<DatabaseDefinitionModel>> _addDefinitions;

Expand All @@ -25,7 +25,7 @@ public PickServerDatabaseDialog(ITelemetryAccess telemetryAccess,
DialogResult = args.DialogResult;
Close();
};
_getDialogResult = () => (viewModel.SelectedDatabaseConnection, viewModel.SelectedDatabaseDefinition);
_getDialogResult = () => (viewModel.SelectedDatabaseConnection, viewModel.SelectedDatabaseDefinition, viewModel.IncludeViews);
_addConnections = models =>
{
foreach (var model in models)
Expand All @@ -45,7 +45,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
DatabaseConnectionCombobox.Focus();
}

public (bool ClosedByOK, (DatabaseConnectionModel Connection, DatabaseDefinitionModel Definition) Payload) ShowAndAwaitUserResponse(bool modal)
public (bool ClosedByOK, (DatabaseConnectionModel Connection, DatabaseDefinitionModel Definition, bool IncludeViews) Payload) ShowAndAwaitUserResponse(bool modal)
{
bool closedByOkay;

Expand Down
8 changes: 4 additions & 4 deletions src/GUI/EFCorePowerTools/Dialogs/PickTablesDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<Setter Property="Margin" Value="0, 0, 5, 0"/>
</Style>
<Style x:Key="NoPrimaryKeyImageStyle" TargetType="Image">
<Setter Property="ToolTip" Value="This table has no primary key defined. It cannot be selected and will be ignored."/>
<Setter Property="Source" Value="/EFCorePowerTools;component/Resources/StatusInvalid_16x.png"/>
<Setter Property="ToolTip" Value="This table (or view) has no primary key defined."/>
<Setter Property="Source" Value="/EFCorePowerTools;component/Resources/TableWarning_16x.png"/>
<Setter Property="Width" Value="16"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Margin" Value="5, 0, 0, 0"/>
</Style>
<Style x:Key="TableNameTextBlockStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Model.HasPrimaryKey}" Value="False">
<DataTrigger Binding="{Binding Model.HasKey}" Value="False">
<Setter Property="Foreground" Value="{StaticResource DisabledTextBlockTextColor}"/>
</DataTrigger>
</Style.Triggers>
Expand Down Expand Up @@ -106,7 +106,7 @@
d:DataContext="{d:DesignInstance Type=viewModels:TableInformationViewModel, IsDesignTimeCreatable=false}">
<CheckBox Style="{StaticResource TableSelectionCheckBoxStyle}"
IsChecked="{Binding IsSelected}"
IsEnabled="{Binding Model.HasPrimaryKey}"/>
IsEnabled="{Binding Model.HasKey}"/>
<TextBlock Text="{Binding Model.Name}"
Style="{StaticResource TableNameTextBlockStyle}"/>
<Image Style="{StaticResource NoPrimaryKeyImageStyle}"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/GUI/EFCorePowerTools/EFCorePowerTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Link>Microsoft.VisualStudio.ProjectSystem.VS.dll</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Dialogs\TableWarning_16x.png" />
<Content Include="efpt\2.1.0\efpt.exe">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
Expand Down Expand Up @@ -184,6 +185,7 @@
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Resources\7.png" />
<Resource Include="Resources\TableWarning_16x.png" />
<Resource Include="Resources\StatusInvalid_16x.png" />
<Resource Include="Resources\Unicorn.png" />
<EmbeddedResource Include="..\ErikEJ.EntityFrameworkCore.DgmlBuilder\template.dgml">
Expand Down
20 changes: 15 additions & 5 deletions src/GUI/EFCorePowerTools/Handlers/ReverseEngineerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public async void ReverseEngineerCodeFirst(Project project)

if (dbInfo == null) dbInfo = new DatabaseInfo();

var includeViews = pickDataSourceResult.Payload.IncludeViews;

if (includeViews && !string.IsNullOrEmpty(dacpacPath))
{
EnvDteHelper.ShowMessage("Dacpac not currently supported with views");
return;
}

if (!string.IsNullOrEmpty(dacpacPath))
{
dbInfo.DatabaseType = DatabaseType.SQLServer;
Expand All @@ -105,13 +113,11 @@ public async void ReverseEngineerCodeFirst(Project project)
return;
}

var result = revEng.GetDacpacTables("xx");

var options = ReverseEngineerOptionsExtensions.TryRead(optionsPath);

List<TableInformationModel> predefinedTables = !string.IsNullOrEmpty(dacpacPath)
? revEng.GetDacpacTables(dacpacPath)
: GetTablesFromRepository(dbInfo);
: GetTablesFromRepository(dbInfo, includeViews);

var preselectedTables = new List<TableInformationModel>();
if (options != null)
Expand Down Expand Up @@ -313,15 +319,19 @@ private List<TableInformationModel> GetTablesFromRepository(DatabaseInfo dbInfo,
foreach (var table in tableList)
{
var hasPrimaryKey = allPks.Any(m => m.TableName == table);
tables.Add(new TableInformationModel(table, hasPrimaryKey));
var info = new TableInformationModel(table, hasPrimaryKey);
info.HasKey = includeViews ? true : hasPrimaryKey;
tables.Add(info);
}

if (includeViews)
{
var views = repository.GetAllViews();
foreach (var view in views)
{
tables.Add(new TableInformationModel(view.ViewName, false));
var info = new TableInformationModel(view.ViewName, false);
info.HasKey = true;
tables.Add(info);
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/GUI/EFCorePowerTools/ViewModels/PickServerDatabaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PickServerDatabaseViewModel : ViewModelBase, IPickServerDatabaseVie

private DatabaseConnectionModel _selectedDatabaseConnection;
private DatabaseDefinitionModel _selectedDatabaseDefinition;
private bool _includeViews;

public event EventHandler<CloseRequestedEventArgs> CloseRequested;

Expand All @@ -29,6 +30,17 @@ public class PickServerDatabaseViewModel : ViewModelBase, IPickServerDatabaseVie
public ObservableCollection<DatabaseConnectionModel> DatabaseConnections { get; }
public ObservableCollection<DatabaseDefinitionModel> DatabaseDefinitions { get; }

public bool IncludeViews
{
get => _includeViews;
set
{
if (value == _includeViews) return;
_includeViews = value;
RaisePropertyChanged();
}
}

public DatabaseConnectionModel SelectedDatabaseConnection
{
get => _selectedDatabaseConnection;
Expand Down
17 changes: 17 additions & 0 deletions src/GUI/RevEng.Shared/TableInformationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TableInformationModel : INotifyPropertyChanged
{
private string _name;
private bool _hasPrimaryKey;
private bool _isKeyLess;

/// <summary>
/// Gets or sets the table name.
Expand Down Expand Up @@ -47,6 +48,21 @@ public bool HasPrimaryKey
}
}

/// <summary>
/// Gets or sets whether a key exists for the table/view or not.
/// </summary>
[IgnoreDataMember]
public bool HasKey
{
get => _isKeyLess;
set
{
if (value == _isKeyLess) return;
_isKeyLess = value;
OnPropertyChanged();
}
}

/// <summary>
/// Initializes a new instance of the <see cref="TableInformationModel"/> class for a specific table.
/// </summary>
Expand All @@ -61,6 +77,7 @@ public TableInformationModel(string name,

Name = name;
HasPrimaryKey = hasPrimaryKey;
HasKey = !hasPrimaryKey;
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down