-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[release/10.0] Fix NullReferenceException when scaffolding named default constraints #37243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
4
commits into
release/10.0
Choose a base branch
from
copilot/fix-test-failure-exception
base: release/10.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−4
Conversation
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
…efault value equals CLR default (#37175) Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
[WIP] Fix test to reproduce exception for issue 37175
Fix NullReferenceException in SqlServerAnnotationCodeGenerator when scaffolding columns with named default constraints and CLR default values
Nov 26, 2025
Copilot finished work on behalf of
AndriySvyryd
November 26, 2025 02:06
Member
|
@copilot Update progress by rewriting the PR summary using this template: |
Contributor
Author
... Updated the PR description with the requested template format. |
Copilot
AI
changed the title
[release/10.0] Fix NullReferenceException when scaffolding named default constraints
Fix NullReferenceException in SqlServerAnnotationCodeGenerator when scaffolding columns with named default constraints and CLR default values
Dec 2, 2025
Copilot finished work on behalf of
AndriySvyryd
December 2, 2025 00:22
cincuranet
approved these changes
Dec 2, 2025
SamMonoRT
approved these changes
Dec 4, 2025
Member
|
cc @artl93 |
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.
Fixes #37175
Description
When scaffolding from a database with
dotnet ef dbcontext scaffold, aNullReferenceExceptionoccurs inSqlServerAnnotationCodeGenerator.GenerateFluentApiCallsfor columns that have both a named default constraint (e.g.,DF_TableName_ColumnName) and a default value equal to the CLR default (e.g.,DEFAULT ((0))forint).The
SqlServerAnnotationCodeGenerator.GenerateFluentApiCallsmethod assumed that ifDefaultConstraintNameexists, eitherDefaultValueorDefaultValueSqlmust also exist. However, the base scaffolding logic inScaffoldingModelExtensions.GenerateAnnotationscan remove these annotations when the default value equals the CLR default, leaving onlyDefaultConstraintName.Customer impact
Scaffolding fails completely when the database contains tables with named default constraints where the default value equals the CLR default (e.g.,
DEFAULT ((0))forint). No workaround exists other than removing the named default constraint from the database or avoiding scaffolding those tables.How found
Customer reported on EF 10
Regression
Yes. This is a regression from EF Core 9.0, introduced by PR #36067 as previously the constraint name was just ignored. #36567 attempted to fix a similar scenario but didn't account for this case.
Testing
Test added
Risk
Low. The fix simply skips generating fluent API code for the constraint name instead of throwing.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.