-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix scaffolding NRT issues #19507
Fix scaffolding NRT issues #19507
Conversation
a3d903d
to
1e77eee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our scaffolding code takes care of constraint names being null in database. We don't throw exception for that. It may not be possible to have null value for SqlServer provider but assumption that it cannot be null in DatabaseModel can be incorrect.
PrincipalTableName: c.GetValueOrDefault<string>("principal_table_name"), | ||
OnDeleteAction: c.GetValueOrDefault<string>("delete_referential_action_desc"))); | ||
PrincipalTableName: c.GetFieldValue<string>("principal_table_name"), | ||
OnDeleteAction: c.GetFieldValue<string>("delete_referential_action_desc"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on delete action can be null. There is nothing in our code says it has be to present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question here is about whether SQL Server can return null or not, not about our model or code. That doesn't seem to be the case according to the docs, but if we feel there's a risk SQL Server will return a NULL here I don't have anything against allowing for that - let me know what you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then consumer of this code can move away from handling value we cannot encounter. Currently it returns null. If we want to make our code future proof if SqlServer change any of this then we need to open that another value can come in. I don't have preference on either way how we read value. Value read and value processing should align on properly, which is not case right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow (see some answers below). The question of how DatabaseModel looks like is separate from how SQL Server specifically scaffolds its information, no?
Thinking more about this
Above is irrespective of DatabaseModel. In DatabaseModel
|
In many cases, being very defensive against future nulls seems a bit much - I doubt we'll ever get rows describing tables where the name is null, for instance. If we're talking about throwing a more informative exception, we could simply fix that if/when it ever actually happens. Existing code before my PR already contained various assumptions about non-nulls coming back, but if we feel it's important to be more defensive against future changes in scaffolding I can make this change.
See previous discussion in #19321 (comment) and @bricelam's suggestion in #19321 (comment). As far as I know constraint names are a standard part of SQL, I'm not aware of any exceptions. This is also somewhat related to the conversation in #19478 (comment) - since I can't imagine an actual valid empty string value, we use that to convey that there was no name in the database, rather than having two possible values (null and empty string). This could be used to implement your suggestion of a default constraint name at runtime. |
Filed #19513 |
That only surface in preview versions of VS. Fixes #19496
1e77eee
to
76a6c43
Compare
@smitpatel tested on VS 16.5.0 Preview 1.0, builds fine (how do I get on the preview 2 channel?). Applied decisions from design:
|
PR changed as discussed in design meeting
That only surface in preview versions of VS.
I've fixed this by using GetFieldValue instead of GetValueOrDefault when reading the relevant database values. I've taken a look (e.g. here) and to my understanding, the affected columns (table/index/key/constraint name, delete referential action) can never be null in the database. In at least some of the cases, our own code would anyway throw immediately afterwards if null was ever returned (@bricelam can you please confirm this looks OK?).
Fixes #19496