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

Support read-only property behaviors #7913

Closed
ajcvickers opened this issue Mar 16, 2017 · 1 comment
Closed

Support read-only property behaviors #7913

ajcvickers opened this issue Mar 16, 2017 · 1 comment
Labels
breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Member

Note: read-only entities is covered by issue #7586. This issue is about read/write entities with read-only properties.

The matrix of behaviors is covered by:

  • Throw if value is set/changed verses ignore any set/changed value
  • Insert or Update
  • Property is store generated or not

For throw scenarios:

  • ReadOnlyBeforeSave throws if value is set before insert
  • ReadOnlyAfterSave throws if value is changed after insert
  • Doesn't matter if value is store generated or not

For ignore scenarios with store-generated values

  • StoreGeneratedAlways means the value set/changed will be ignored for insert or update
  • Missing: way to say store-generated on update only
  • Missing: way to say StoreGeneratedAlways for insert, but not update
  • Missing: way to say StoreGeneratedAlways for update, but not insert

For ignore scenarios without store-generated values

  • Problem with this is that after SaveChanges the database may have a different value than the client. This seems like it is usually a bad thing, and hence if value should be ignored, then it really should be made store generated.
  • However, if people are okay with the value being different, and all consequences of this (fixup for FKs, etc.), then if we support StoreGeneratedAlways for all properties (changing semantics to mean ignore set/changed value) and add missing options listed above, then this would "just work".

Proposal:

  • Change StoreGeneratedAlways to IgnoreValueBeforeSave and IgnoreValueAfterSave. This allows it to be set differently for inserts and updates in the same way that read-only can be.
  • Respect this flag even if property is not marked store generated
  • Introduce ValueGenerator.OnUpdate to support insert a value but then read-only/ignore after that

No fluent API for now, but in the future consider adding it for most common combinations.

@ajcvickers
Copy link
Member Author

Design meeting notes:

  • Decided to do this, although not all of it is high priority
  • Would be good to combine ReadOnly... and IgnoreValue... APIs into enum, possibly obsoleting the old APIs for now
  • If we add OnUpdate, then we should change the enum to be a flags enum; makes the breaking change cleaner but with higher impact, but makes it more likely that providers will react correctly to the break.

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview2, 2.0.0 May 15, 2017
ajcvickers added a commit that referenced this issue May 20, 2017
Part of issue #7913

This change obsoletes ReadOnlyBeforeSave, ReadOnlyAferSave, and StoreGeneratedAlways into two unified facets--one for before-save behavior (Added objects) and one for after-save behavior. In each case the property value can be:
- Ignore: value never sent to database. (Equivalent to StoreGeneratedAlways, but can apply to any property and can be set differently for before and after save.)
- Throw: any non-CLR default value set or property marked as modified causes exception. (Equivalent to previous read-only behaviors.)
- UseValue: the value is used if it has been set (to non-CLR default for store-generated) or marked as modified.

Also covers issue #7914 - makes Ignore the default for before and after save when using AddOrUpdate (computed) properties.
ajcvickers added a commit that referenced this issue May 20, 2017
Part of issue #7913

This change obsoletes ReadOnlyBeforeSave, ReadOnlyAferSave, and StoreGeneratedAlways into two unified facets--one for before-save behavior (Added objects) and one for after-save behavior. In each case the property value can be:
- Ignore: value never sent to database. (Equivalent to StoreGeneratedAlways, but can apply to any property and can be set differently for before and after save.)
- Throw: any non-CLR default value set or property marked as modified causes exception. (Equivalent to previous read-only behaviors.)
- UseValue: the value is used if it has been set (to non-CLR default for store-generated) or marked as modified.

Also covers issue #7914 - makes Ignore the default for before and after save when using AddOrUpdate (computed) properties.
ajcvickers added a commit that referenced this issue May 21, 2017
Second part of issue #7913

This change adds a new ValueGenerated option for requiring a value on insert, but then using the value from the store for subsequent updates. This is a binary breaking change, but not a functional breaking change after a re-compile.
ajcvickers added a commit that referenced this issue May 23, 2017
Part of issue #7913

This change obsoletes ReadOnlyBeforeSave, ReadOnlyAferSave, and StoreGeneratedAlways into two unified facets--one for before-save behavior (Added objects) and one for after-save behavior. In each case the property value can be:
- Ignore: value never sent to database. (Equivalent to StoreGeneratedAlways, but can apply to any property and can be set differently for before and after save.)
- Throw: any non-CLR default value set or property marked as modified causes exception. (Equivalent to previous read-only behaviors.)
- UseValue: the value is used if it has been set (to non-CLR default for store-generated) or marked as modified.

Also covers issue #7914 - makes Ignore the default for before and after save when using AddOrUpdate (computed) properties.
ajcvickers added a commit that referenced this issue May 23, 2017
Second part of issue #7913

This change adds a new ValueGenerated option for requiring a value on insert, but then using the value from the store for subsequent updates. This is a binary breaking change, but not a functional breaking change after a re-compile.
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 24, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview2, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware type-enhancement
Projects
None yet
Development

No branches or pull requests

1 participant