Skip to content

ensure that hard there are no hard coded values in the templates#3723

Merged
haileymck merged 2 commits intomainfrom
dev/hmckelvie/fix-2941859
Apr 20, 2026
Merged

ensure that hard there are no hard coded values in the templates#3723
haileymck merged 2 commits intomainfrom
dev/hmckelvie/fix-2941859

Conversation

@haileymck
Copy link
Copy Markdown
Member

fix AzDo bug
This bug is coming from the fact that some values in the template files used for code generation are hard coded. This change removes those hard coded values that were causing these errors. Furthermore, additional tests are added.

drewnoakes
drewnoakes previously approved these changes Apr 17, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes hard-coded sample values (e.g., “movie”, “Title,ReleaseDate,Genre,Price”) from the MVC EF controller scaffolding templates by deriving [Bind] property lists and parameter names from the actual model metadata, and adds regression tests to prevent reintroducing the issue.

Changes:

  • Update net9/net10/net11 MvcEfController templates to generate [Bind] lists from Model.ModelInfo.ModelProperties and use the model name for action parameter naming.
  • Update the checked-in generated .cs outputs for the templates accordingly.
  • Add template regression tests validating no hard-coded “movie”/Movie-property values appear in generated output.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
test/dotnet-scaffolding/dotnet-scaffold.Tests/AspNet/Templates/MvcEfControllerTemplateTests.cs Adds regression tests for [Bind]/parameter naming and removal of hard-coded “movie” values.
test/dotnet-scaffolding/dotnet-scaffold.Tests/AspNet/ScaffoldSteps/AddDbSetToExistingContextStepTests.cs Present in PR metadata (file currently empty).
src/dotnet-scaffolding/dotnet-scaffold/AspNet/Templates/net9.0/EfController/MvcEfController.tt Derives [Bind] values and parameter name from model metadata (net9).
src/dotnet-scaffolding/dotnet-scaffold/AspNet/Templates/net9.0/EfController/MvcEfController.cs Regenerated output reflecting updated net9 template logic.
src/dotnet-scaffolding/dotnet-scaffold/AspNet/Templates/net10.0/EfController/MvcEfController.tt Derives [Bind] values from model metadata (net10).
src/dotnet-scaffolding/dotnet-scaffold/AspNet/Templates/net10.0/EfController/MvcEfController.cs Regenerated output reflecting updated net10 template logic.
src/dotnet-scaffolding/dotnet-scaffold/AspNet/Templates/net11.0/EfController/MvcEfController.tt Derives [Bind] values from model metadata (net11).
src/dotnet-scaffolding/dotnet-scaffold/AspNet/Templates/net11.0/EfController/MvcEfController.cs Regenerated output reflecting updated net11 template logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

string primaryKeyName = Model.ModelInfo.PrimaryKeyName;
string primaryKeyNameLowerInv = primaryKeyName.ToLowerInvariant();
string primaryKeyTypeName = Model.ModelInfo.PrimaryKeyTypeName;
string bindProperties = string.Join(",", Model.ModelInfo.ModelProperties?.Select(p => p.Name) ?? Enumerable.Empty<string>());
string primaryKeyName = Model.ModelInfo.PrimaryKeyName;
string primaryKeyNameLowerInv = primaryKeyName.ToLowerInvariant();
string primaryKeyTypeName = Model.ModelInfo.PrimaryKeyTypeName;
string bindProperties = string.Join(",", Model.ModelInfo.ModelProperties?.Select(p => p.Name) ?? Enumerable.Empty<string>());
Comment on lines +39 to +41
// Assert – must contain the real property names, not "Title,ReleaseDate,Genre,Price"
Assert.Contains("[Bind(\"BlogId,Url\")]", result);
}
Comment on lines +165 to +166
int bindOccurrences = CountOccurrences(result, "[Bind(\"BlogId,Url\")]");
Assert.Equal(2, bindOccurrences);
string primaryKeyName = Model.ModelInfo.PrimaryKeyName;
string primaryKeyNameLowerInv = primaryKeyName.ToLowerInvariant();
string primaryKeyTypeName = Model.ModelInfo.PrimaryKeyTypeName;
string bindProperties = string.Join(",", Model.ModelInfo.ModelProperties?.Select(p => p.Name) ?? Enumerable.Empty<string>());
string primaryKeyName = Model.ModelInfo.PrimaryKeyName;
string primaryKeyNameLowerInv = primaryKeyName.ToLowerInvariant();
string primaryKeyTypeName = Model.ModelInfo.PrimaryKeyTypeName;
string bindProperties = string.Join(",", Model.ModelInfo.ModelProperties?.Select(p => p.Name) ?? Enumerable.Empty<string>());
PrimaryKeyShortTypeName = "int",
ModelProperties = properties
},
ProjectInfo = new AspNetProjectInfo(Path.Combine("test", "TestProject.csproj"))
string primaryKeyName = Model.ModelInfo.PrimaryKeyName;
string primaryKeyNameLowerInv = primaryKeyName.ToLowerInvariant();
string primaryKeyTypeName = Model.ModelInfo.PrimaryKeyTypeName;
string bindProperties = string.Join(",", Model.ModelInfo.ModelProperties?.Select(p => p.Name) ?? Enumerable.Empty<string>());
string primaryKeyName = Model.ModelInfo.PrimaryKeyName;
string primaryKeyNameLowerInv = primaryKeyName.ToLowerInvariant();
string primaryKeyTypeName = Model.ModelInfo.PrimaryKeyTypeName;
string bindProperties = string.Join(",", Model.ModelInfo.ModelProperties?.Select(p => p.Name) ?? Enumerable.Empty<string>());
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@haileymck haileymck merged commit ca4f160 into main Apr 20, 2026
8 checks passed
@haileymck haileymck deleted the dev/hmckelvie/fix-2941859 branch April 20, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants