-
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
Warn if a non-key property is configured as PropertySaveBehavior.Throw #23786
Comments
@roryap The problem here is that EF Core doesn't actually know whether or not the property has been modified or not. This is because entity to be updated is changed while it is not being tracked, and then it is tracked again with a call to This works correctly if:
I'm been writing a lot about this recently in the new docs on change tracking--PR here: dotnet/EntityFramework.Docs#2972 We will discuss this behavior, since I agree it is confusing. It may be worthwhile to output a warning if Update is used and any values other than keys are marked as AfterSave.Throw. |
A warning would be great. Just something to trigger some behavior, e.g. throwing my own exception. I'm (obviously) using it in a disconnected way, which I cannot change. |
Note from triage: we will warn if a non-key property is marked to throw after save, but then an attempt is made to set all properties as modified. |
See attached project. I am trying to make it so an exception is thrown when a change is made to a certain property after the initial insert. I'm using
entity.Property(nameof(MyClass.Name)).Metadata.SetAfterSaveBehavior(PropertySaveBehavior.Throw);
but the save is successful (no ex) and the property remains unchanged.EF Core PropertySaveBehavior.Throw Issue.zip
EF Core version: 5.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows 10 Pro (1.0.19042)
IDE: Visual Studio 2019 16.8.2
The text was updated successfully, but these errors were encountered: