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

Improve backing field modeling page #2005

Merged
merged 2 commits into from
Jan 14, 2020
Merged

Improve backing field modeling page #2005

merged 2 commits into from
Jan 14, 2020

Conversation

roji
Copy link
Member

@roji roji commented Dec 20, 2019

  • Reorganize content based on topics and not convention/fluent API/data annotations, as done in Merge relational database modeling into general modeling #1669.
  • Correct the documentation of the default property access mode (change from PreferFieldDuringConstruction to PreferField in 3.0), and add a note on the behavior change.
  • Various other cleanups and improvements.

* Reorganize content based on topics and not convention/fluent API/data annotations, as done in #1669.
* Correct the documentation of the default property access mode (change from PreferFieldDuringConstruction to PreferField in 3.0), and add a note on the behavior change.
* Various other cleanups and improvements.
@ajcvickers ajcvickers self-requested a review January 6, 2020 18:45
@roji roji requested a review from AndriySvyryd January 6, 2020 18:51

[!code-csharp[Main](../../../samples/core/Modeling/FluentAPI/BackingField.cs#Sample)]
By default, EF will always read and write to the backing field - assuming one has been properly configured - and will never use the property. However, EF also supports other access patterns. For example, the following sample instructs EF to write to the backing field only while materializing, and to use the property in all other cases:
Copy link
Member

Choose a reason for hiding this comment

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

I think this is misleading. By default, EF will always read and write to the backing field so long as the backing field has been discovered or configured as described above. The property will be used if the backing field is not known.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think that "assuming one has been properly configured" isn't sufficient here? Maybe "assuming one has been properly discovered or configured", or something else?


You can also create a conceptual property in your model that does not have a corresponding CLR property in the entity class, but instead uses a field to store the data in the entity. This is different from [Shadow Properties](shadow-properties.md), where the data is stored in the change tracker. This would typically be used if the entity class uses methods to get/set values.
Copy link
Member

Choose a reason for hiding this comment

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

I would not necessarily call this the "typical" case, even though it is a common case. Another common case is for fields that should not be exposed at all in the domain model, such as primary keys.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed a change, let me know what you think.

Copy link
Member

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

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

Couple of minor comments.

@roji roji merged commit 98c47f8 into master Jan 14, 2020
@smitpatel smitpatel deleted the BackingFieldCleanup branch February 5, 2020 16:26
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.

2 participants