Skip to content

Commit

Permalink
add validation for index column names (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvreony authored Sep 19, 2024
1 parent 516a420 commit 1b4d68a
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,16 @@ private static void GenerateIndexDeclarations(IEntityGenerationModel entityGener

private static ExpressionStatementSyntax GetIndexDeclarationExpressionStatementSyntax(IndexGenerationModel index)
{
var args = index.Names.Select(n => $"t.{n}");
var names = index.Names;

if (names == null || names.Length == 0)
{
throw new ArgumentException("Index must have at least one column name", nameof(index));
}



var args = GetIndexColumnNames(names);

var flattedPropertyNames = string.Join(", ", args);

Expand All @@ -571,6 +580,20 @@ private static ExpressionStatementSyntax GetIndexDeclarationExpressionStatementS
return statement;
}

private static IEnumerable<string> GetIndexColumnNames(string[] names)
{
for (var index = 0; index < names.Length; index++)
{
var name = names[index];
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException($"Index at position {index} has a column name that is null or whitespace.", nameof(names));
}

yield return $"t.{name.Trim()}Id";
}
}

private ExpressionSyntax CheckHasComputedColumnSqlMethodDeclaration(ExpressionSyntax fluentApiInvocation, string sqlComputedColumn)
{
if (sqlComputedColumn == null)
Expand Down

0 comments on commit 1b4d68a

Please sign in to comment.