Skip to content

Commit

Permalink
Scaffolding: Handle unknown computed column SQL in model factory (#32251
Browse files Browse the repository at this point in the history
)

Fixes #32179
  • Loading branch information
bricelam authored Nov 8, 2023
1 parent e4ff864 commit 9ea08b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!--
When StabilizePackageVersion is set to 'true', this branch will produce stable outputs for 'Shipping' packages
-->
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">true</StabilizePackageVersion>
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
<DefaultNetCoreTargetFramework>net8.0</DefaultNetCoreTargetFramework>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,14 @@ protected virtual EntityTypeBuilder VisitColumns(EntityTypeBuilder builder, ICol

if (column.ComputedColumnSql != null)
{
property.HasComputedColumnSql(column.ComputedColumnSql, column.IsStored);
if (column.ComputedColumnSql.Length == 0)
{
property.HasComputedColumnSql();
}
else
{
property.HasComputedColumnSql(column.ComputedColumnSql, column.IsStored);
}
}

if (column.Comment != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3072,4 +3072,36 @@ void AssertNavigations()
}
);
}

[ConditionalFact]
public void Computed_column_when_sql_unknown()
{
var database = new DatabaseModel
{
Tables =
{
new DatabaseTable
{
Database = Database,
Name = "Table",
Columns =
{
IdColumn,
new DatabaseColumn
{
Table = Table,
Name = "Column",
StoreType = "int",
ComputedColumnSql = string.Empty
}
}
}
}
};

var model = _factory.Create(database, new ModelReverseEngineerOptions());

var column = model.FindEntityType("Table").GetProperty("Column");
Assert.Empty(column.GetComputedColumnSql());
}
}

0 comments on commit 9ea08b9

Please sign in to comment.