ensure that hard there are no hard coded values in the templates#3723
Merged
ensure that hard there are no hard coded values in the templates#3723
Conversation
c32e834 to
61bcb90
Compare
drewnoakes
previously approved these changes
Apr 17, 2026
Contributor
There was a problem hiding this comment.
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
MvcEfControllertemplates to generate[Bind]lists fromModel.ModelInfo.ModelPropertiesand use the model name for action parameter naming. - Update the checked-in generated
.csoutputs 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>
drewnoakes
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.