Skip to content
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

Nullability annotation for scaffolding #19321

Merged
merged 1 commit into from
Dec 24, 2019
Merged

Nullability annotation for scaffolding #19321

merged 1 commit into from
Dec 24, 2019

Conversation

roji
Copy link
Member

@roji roji commented Dec 14, 2019

Saturday project: NRT annotations for all of scaffolding.

@roji roji requested a review from bricelam December 14, 2019 13:25

/// <summary>
/// The foreign key constraint name.
/// </summary>
public virtual string Name { get; [param: CanBeNull] set; }
public virtual string Name { get; [param: NotNull] set; }
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about the nullability of this (also for other constraints/index).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking about this again, we may want to simply leave the names of constraints and index nullable, for databases which don't support them? Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

Better err on the nullable side

Copy link
Member Author

@roji roji Dec 24, 2019

Choose a reason for hiding this comment

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

Looked at this again. Before my changes, name is "nullable" (has [CanBeNull]) on DatabaseForeignKey, DatabasePrimaryKey, but not on DatabaseIndex and DatabaseUniqueConstraint.

As @bricelam suggested, am going to leave all these non-nullable with the idea that providers can set these to empty string if they don't support a name. Otherwise we'd have two options - both null and empty string - which doesn't seem to make much sense... We can change this if anyone has any strong feelings about it.

@roji roji force-pushed the ScaffoldingNullability branch 4 times, most recently from 9e7cab4 to e58e2d7 Compare December 14, 2019 17:01
@ajcvickers
Copy link
Contributor

@roji @AndriySvyryd @bricelam What would be a good way forward with this? Should we discuss the non-obvious/questionable cases in a design meeting? That might also help the team develop a consistent approach to these things.

@roji
Copy link
Member Author

roji commented Dec 17, 2019

To be honest the open questions seem a bit minor to me (in the specific case of scaffolding), I think @bricelam could probably just provide some of the answers and we could finalize here in writing. But we can definitely discuss tomorrow, shouldn't take to long.

@@ -47,21 +56,19 @@ public void Creates_entity_types()
{
Tables =
{
new DatabaseTable
new DatabaseTable(Database, "tableWithSchema")
Copy link
Contributor

Choose a reason for hiding this comment

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

There was code somewhere in the tests to fix up back references. It can be removed now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you're talking about FakeScaffoldingModelFactory.Create - removed that method. We can maybe kill FakeScaffoldingModelFactory altogether (it doesn't do anything anymore), but leaving it in for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually ended up bringing the fixup back, since we in our tests we create "incorrect" models, which this code rectifies; for example, in Column_ordinal_annotation we create a new DatabaseTable, but the columns inserted into it refer back to the test suite's global Table instance (not the same). We could go over tests and fix this, but it would make test code more cumbersome as we wouldn't be able to use object initializers as now.

If we this is worth it I'll do it, for now will merge with the fixup code as before.

var resultingFiles = new ScaffoldedModel();
if (options.ContextName == null)
{
throw new ArgumentException($"{nameof(options.ContextName)} cannot be null", nameof(options));
Copy link
Contributor

Choose a reason for hiding this comment

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

Check.NotNull?

Copy link
Member Author

Choose a reason for hiding this comment

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

To be super pedantic about it, if options.ContextName is null, it's problematic for GenerateModel to throw ArgumentNullException, since the argument itself isn't null but rather some property on it :)

Will leave like this for now, but am fine changing if anyone cares enough about it.

@roji roji force-pushed the ScaffoldingNullability branch from e58e2d7 to f481b97 Compare December 24, 2019 18:47
@roji roji force-pushed the ScaffoldingNullability branch from f481b97 to a356758 Compare December 24, 2019 18:53
@roji roji merged commit eab93af into master Dec 24, 2019
@roji roji deleted the ScaffoldingNullability branch December 24, 2019 19:39
@ajcvickers
Copy link
Contributor

@roji I'm reverting this because it's preventing me from building, which is spoiling my vacation!

image

@roji
Copy link
Member Author

roji commented Dec 25, 2019

Huh? That's weird... You've got the latest VS and whatever "other IDE-related tools" you're using right? Can you at least confirm whether a cmdline build work with the latest dotnet SDK 3.1?

Otherwise if this commit is preventing you from working during vacation it may be a good commit :) But sure, if stuff doesn't work we can investigate later and re-merge.

@roji roji mentioned this pull request Jan 7, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 25, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 25, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 28, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 28, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 28, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 28, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Jan 29, 2020
roji added a commit to roji/efcore.pg that referenced this pull request Feb 1, 2020
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.

4 participants