Skip to content

Commit

Permalink
Enable support for getting views from SQL Server, SQLite and dacpac
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ committed Jun 29, 2019
1 parent 1a5d48d commit 63f7129
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/GUI/EFCorePowerTools/EFCorePowerTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.107.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<Reference Include="System.Data.SQLite, Version=1.0.110.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<HintPath>..\lib\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Design" />
Expand Down
12 changes: 11 additions & 1 deletion src/GUI/EFCorePowerTools/Handlers/ReverseEngineerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public async void ReverseEngineerCodeFirst(Project project)
}
}

private List<TableInformationModel> GetTablesFromRepository(DatabaseInfo dbInfo)
private List<TableInformationModel> GetTablesFromRepository(DatabaseInfo dbInfo, bool includeViews = false)
{
if (dbInfo.DatabaseType == DatabaseType.Npgsql)
{
Expand All @@ -310,6 +310,16 @@ private List<TableInformationModel> GetTablesFromRepository(DatabaseInfo dbInfo)
var hasPrimaryKey = allPks.Any(m => m.TableName == table);
tables.Add(new TableInformationModel(table, hasPrimaryKey));
}

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

return tables;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ public DacpacTableListBuilder(string dacpacPath)
_dacpacPath = dacpacPath;
}

public List<TableInformationModel> GetTableDefinitions()
public List<TableInformationModel> GetTableDefinitions(bool includeViews = false)
{
var model = new TSqlTypedModel(_dacpacPath);
return model.GetObjects<TSqlTable>(DacQueryScopes.UserDefined)
var result = model.GetObjects<TSqlTable>(DacQueryScopes.UserDefined)
.Select(m => new TableInformationModel(m.Name.Parts[0] + "." + m.Name.Parts[1], m.PrimaryKeyConstraints.Any()))
.ToList();

if (includeViews)
{
var views = model.GetObjects<TSqlView>(DacQueryScopes.UserDefined)
.Select(m => new TableInformationModel(m.Name.Parts[0] + "." + m.Name.Parts[1], false))
.ToList();
result = result.Concat(views).ToList();
}

return result;
}
}
}
Binary file modified src/GUI/lib/ISqlCeScripting.dll
Binary file not shown.
Binary file modified src/GUI/lib/SQLiteScripting.dll
Binary file not shown.
Binary file modified src/GUI/lib/SqlCeScripting.dll
Binary file not shown.
Binary file modified src/GUI/lib/SqlCeScripting40.dll
Binary file not shown.
Binary file modified src/GUI/lib/System.Data.SQLite.dll
Binary file not shown.

0 comments on commit 63f7129

Please sign in to comment.