Skip to content

Commit

Permalink
DAB: Exclude columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ committed Jul 29, 2024
1 parent 33d37fc commit ed9c4a2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/Core/RevEng.Core.80/DataApiBuilderBuilder/DabBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public string GetDabConfigCmdFile()
continue;
}

RemoveExcludedColumns(dbObject);

var columnList = string.Join(
",",
dbObject.Columns
Expand All @@ -126,6 +128,8 @@ public string GetDabConfigCmdFile()
continue;
}

RemoveExcludedColumns(dbObject);

var columnList = string.Join(
",",
dbObject.Columns
Expand Down Expand Up @@ -202,6 +206,22 @@ private static bool BreaksOn(DatabaseTable dbObject)
|| !dbObject.Columns.Any();
}

private void RemoveExcludedColumns(DatabaseTable dbObject)
{
var excludedColumns = options.Tables.Find(t => t.Name == $"[{dbObject.Schema}].[{dbObject.Name}]")?.ExcludedColumns;
if (excludedColumns != null)
{
foreach (var column in excludedColumns)
{
var columnToRemove = dbObject.Columns.FirstOrDefault(c => c.Name.Equals(column, StringComparison.OrdinalIgnoreCase));
if (columnToRemove != null)
{
dbObject.Columns.Remove(columnToRemove);
}
}
}
}

private DatabaseModel GetModelInternal()
{
var dbModelFactory = serviceProvider.GetService<IDatabaseModelFactory>();
Expand Down
6 changes: 5 additions & 1 deletion src/Core/efreveng60/TestFiles/dabtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
},
{
"Name": "[dbo].[Customers]",
"ObjectType": 0
"ObjectType": 0,
"ExcludedColumns": [
"Fax",
"Phone"
]
},
{
"Name": "[dbo].[Employees]",
Expand Down
Binary file modified src/GUI/lib/efreveng80.exe.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions test/Ef7Playground/Ef7Playground/dab-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"ObjectType": 0
},
{
"ExcludedColumns": [
"PostalCode",
"Phone",
"Fax",
"Email"
],
"Name": "[dbo].[Customer]",
"ObjectType": 0
},
Expand Down
2 changes: 1 addition & 1 deletion test/ScaffoldingTester/ScaffoldingTester5/dab-config.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dab init -c dab-config.json --database-type mssql --connection-string "@env('dab
dab add "Categories" --source "[dbo].[Categories]" --fields.include "CategoryID,CategoryName,Description,Picture" --permissions "anonymous:*"
dab add "CustomerCustomerDemo" --source "[dbo].[CustomerCustomerDemo]" --fields.include "CustomerID,CustomerTypeID" --permissions "anonymous:*"
dab add "CustomerDemographics" --source "[dbo].[CustomerDemographics]" --fields.include "CustomerTypeID,CustomerDesc" --permissions "anonymous:*"
dab add "Customers" --source "[dbo].[Customers]" --fields.include "CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,Rating" --permissions "anonymous:*"
dab add "Customers" --source "[dbo].[Customers]" --fields.include "CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Rating" --permissions "anonymous:*"
dab add "Employees" --source "[dbo].[Employees]" --fields.include "EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath" --permissions "anonymous:*"
dab add "EmployeeTerritories" --source "[dbo].[EmployeeTerritories]" --fields.include "EmployeeID,TerritoryID" --permissions "anonymous:*"
dab add "OrderDetails" --source "[dbo].[Order Details]" --fields.include "OrderID,ProductID,UnitPrice,Quantity,Discount" --permissions "anonymous:*"
Expand Down

0 comments on commit ed9c4a2

Please sign in to comment.