Skip to content

Commit

Permalink
Support Sql computed column code generation (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Smitha Saligrama <[email protected]>
  • Loading branch information
smithago and smithago authored Apr 6, 2020
1 parent 3aca8b0 commit bbd93a8
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,22 @@ private static string GetTableTypeNameWithoutVersionSuffix(SchemaObjectName obje
protected MemberDeclarationSyntax CreatePropertyForColumn(ColumnDefinition column)
{
string normalizedSqlDbType = null;
var sqlDbTypeToNormalize = column.DataType.Name.BaseIdentifier.Value;

// Handle computed columns
if (column.DataType == null && column.ComputedColumnExpression != null)
{
return FieldDeclaration(
VariableDeclaration(SyntaxFactory.ParseTypeName("string"))
.AddVariables(VariableDeclarator($"{column.ColumnIdentifier.Value}")
.WithInitializer(
EqualsValueClause(
LiteralExpression(
SyntaxKind.StringLiteralExpression,
Literal(column.ColumnIdentifier.Value))))))
.AddModifiers(Token(SyntaxKind.InternalKeyword), Token(SyntaxKind.ConstKeyword));
}

var sqlDbTypeToNormalize = column.DataType.Name.BaseIdentifier.Value;
if (Enum.TryParse(sqlDbTypeToNormalize, true, out SqlDbType sqlDbType))
{
normalizedSqlDbType = sqlDbType.ToString();
Expand Down

0 comments on commit bbd93a8

Please sign in to comment.