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

Document C# 8 nullable reference types #1709

Merged
merged 1 commit into from
Sep 23, 2019
Merged

Document C# 8 nullable reference types #1709

merged 1 commit into from
Sep 23, 2019

Conversation

roji
Copy link
Member

@roji roji commented Sep 9, 2019

Closes #1654
Closes #1655

@roji roji force-pushed the NRT branch 3 times, most recently from bab0353 to 4d01b62 Compare September 9, 2019 14:49
@roji
Copy link
Member Author

roji commented Sep 9, 2019

So there's a new "nullable reference types" under "miscellaneous" (which is accessible under "fundamentals" in the site TOC, we're changing that right?), plus some additional changes in other pages.

  • In some cases the code sample shown in the doc page is huge, anyone know if we can show a subset of lines (not highlight)?
  • The sample depends on 3.0.0-preview9, we'll need to update that when we RTM

Copy link
Contributor

@divega divega left a comment

Choose a reason for hiding this comment

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

Some suggestions.

@@ -0,0 +1,64 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this file to the ToC?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do, but was hesitating where to put it. As it's cross-cutting (modeling, querying...), it seems like it would fit well in a Miscellaneous section - see #1726. Will add it under Fundamentals for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you are right, and this got me thinking... Whether we add or not an article focused on nullable reference types to the EF Core docs, the main thing we should be focusing on is making sure we enhance existing pages with information relevant to nullable reference types.

For example:

  • The main place information on nullable reference types is in core/modeling/required-optional article. Adding the information there is coherent with the fact that form the EF Core perspective, there is a single concept of nullability/requiredness, and we want to treat nullable value types, nullable reference types and the [Required] attribute all the same as much as possible.
  • The part about initialization belongs in some topic about modeling entity properties.
  • Though the comments specific to the initialization of DbSets belongs probably in working with DbContext.

Understandably nullable reference types are new and us and our customers have learned a lot about them very recently, but if we make nullable reference types too special in the EF Core docs, I don't think that is great. Long term NRT should become routine, more or less just like using Nullable<T> is routine today, and we don't maintain a dedicated page about Nullable<T> in the EF Core docs.

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 agree that we should add NRT-related notes to the property modeling articles and DbSet/DbContext articles. At the same time, at least in the foreseeable future NRTs is a new feature and we should probably have a dedicated page for migrating to it, much like we have an EF6->Core migration page - just to concentrate all the relevant information in a single place for people thinking about moving and wanting to understand all the consequences.

Some links back and forth are OK, and if we end up with some duplication I don't think it's the end of the world either...

If that sounds good I'll work on refactoring the information into the specific articles too.

Copy link
Contributor

@divega divega Sep 16, 2019

Choose a reason for hiding this comment

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

Yeah, sounds good if you are convinced. Though I prefer the dedicated page to be mostly links to the other ones. As you say, it is a cross cutting feature. We need the information to be included where it matters. Also, new features are supposed to go in “what’s new”, and aspects of migrating to new versions can go to an article about upgrading to 3.0. We have an issue for creating the later.


This page introduces EF Core's support fo nullable reference types, and describes best practices for working with them.

## Required and optional properties
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider only including a short paragraph and a link to the required-optional article rather than entirely duplicating its contents here.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Note that means we'd have links going both ways, but it seems fine.

@@ -0,0 +1,64 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you are right, and this got me thinking... Whether we add or not an article focused on nullable reference types to the EF Core docs, the main thing we should be focusing on is making sure we enhance existing pages with information relevant to nullable reference types.

For example:

  • The main place information on nullable reference types is in core/modeling/required-optional article. Adding the information there is coherent with the fact that form the EF Core perspective, there is a single concept of nullability/requiredness, and we want to treat nullable value types, nullable reference types and the [Required] attribute all the same as much as possible.
  • The part about initialization belongs in some topic about modeling entity properties.
  • Though the comments specific to the initialization of DbSets belongs probably in working with DbContext.

Understandably nullable reference types are new and us and our customers have learned a lot about them very recently, but if we make nullable reference types too special in the EF Core docs, I don't think that is great. Long term NRT should become routine, more or less just like using Nullable<T> is routine today, and we don't maintain a dedicated page about Nullable<T> in the EF Core docs.

> [!NOTE]
> Exercise caution when enabling nullable reference types on an existing project: reference type properties which were previously configured as optional will now be configured as required, unless they are explicitly annotated to be nullable. When managing a relational database schema, this may cause migrations to be generated which alter the database column's nullability.

## DbContext and DbSet
Copy link
Contributor

Choose a reason for hiding this comment

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

This entire section would probably go into core/miscellaneous/configuring-dbcontext. The only problem is that we don't have there the basics of adding DbSets to include a type in the model.

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 find that page a bit confusing and not necessarily suitable for newcomers (e.g. it starts with "Design-time DbContext configuration" which seems very specific and somewhat advanced). I think core/modeling/index could be a better candidate. But see also my comments above on a specific nullability page etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree the configuring DbContext page can be improved, reorganized, and that some of the more basic/introductory content is currently missing from it. However it exists for good reasons and many of the more advanced things including in it are there because they happen to be too common pitfalls that we have been forced to document.

If the root modeling page is a better candidate to explain how the DbSets on the DbContext contribute to the model, I guess the configuring DbContext page should have a paragraph and a link to that page too.

> [!NOTE]
> Exercise caution when enabling nullable reference types on an existing project: reference type properties which were previously configured as optional will now be configured as required, unless they are explicitly annotated to be nullable. When managing a relational database schema, this may cause migrations to be generated which alter the database column's nullability.

## DbContext and DbSet
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree the configuring DbContext page can be improved, reorganized, and that some of the more basic/introductory content is currently missing from it. However it exists for good reasons and many of the more advanced things including in it are there because they happen to be too common pitfalls that we have been forced to document.

If the root modeling page is a better candidate to explain how the DbSets on the DbContext contribute to the model, I guess the configuring DbContext page should have a paragraph and a link to that page too.

@roji
Copy link
Member Author

roji commented Sep 23, 2019

@divega I've merged your suggestions. I agree that we should integrate NRT information in various relevant pages rather than only in a single page (#1709 (comment)), but that requires a more complete rethinking/restructuring of the docs (interacts with modeling changes in #1669, work on the DbContext page, etc.). So unless you object I suggest we merge this PR as-is - it's sub-optimal but it does provide complete information right away for 3.0. I'll open a separate issue to track introducing NRT information into the other relevant pages, link back and forth etc.

Does that sound OK?

@roji roji marked this pull request as ready for review September 23, 2019 09:33
@roji
Copy link
Member Author

roji commented Sep 23, 2019

Note: am working on some further improvements on this PR, especially with regards to the samples.

@roji roji force-pushed the NRT branch 6 times, most recently from 933d29e to 4406495 Compare September 23, 2019 12:32
@divega
Copy link
Contributor

divega commented Sep 23, 2019

Does that sound OK?

I am ok with this plan.

@roji roji force-pushed the NRT branch 2 times, most recently from 61543ee to e9f3d09 Compare September 23, 2019 12:41
@roji
Copy link
Member Author

roji commented Sep 23, 2019

I am ok with this plan.

Thanks @divega! Have made some improvements and will merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants