-
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
Using a navigation property to clear a foreign key fails in 2.0.0 #9466
Comments
@svallis We made some changes to the way DeleteBehaviors work in 2.0. I can't find the announcement for this (@divega--do you know where it is?) but here is the draft I wrote for it in #8923:
So it looks like you need to configure the relationship as DeleteBehavior.ClientSetNull, or just don't configure it at all since this is the default. Question: why were you explicitly configuring Restrict in your 1.1.x code? We were expecting this to be quite rare since it was the default for optional relationships anyway. |
@ajcvickers I ended up not creating announcements for many of the changes. Instead this information was added to the documentation, both in the cascade delete topic and on https://docs.microsoft.com/en-us/ef/core/miscellaneous/1x-2x-upgrade. I am also planning to update that topic with additional information for Visual Studio 2015 and .NET Framework users that I have been adding to the prerequisite section of the announcement blog post. That way we can have a single resource that we can keep up to date and we can point customers too. Then an announcement pointing to that topic should help. Thoughts? |
Thanks for the responses.
Bear in mind this code base has been around since pre 1.0.0. Some of the foreign keys were being created in my migrations with
Commenting that out in 2.0.0 and generating a new migration is still trying to create |
@divega Sounds good. |
@svallis Thanks for the information. Glad it is working for you now. (FYI: relationships get cascade delete by convention when the FK is not nullable.) |
Hi @svallis. We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:
Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward. |
Did you consider testing your code against the pre-release builds? Was there anything blocking you from using pre-release builds? What do you think could make it easier for you to use pre-release builds in the future? |
@svallis Thanks for the feedback; much appreciated! Curious, how long would you consider it acceptable to wait for the x.x.1 version? |
@ajcvickers I don't think there's a fixed time-frame, it'd always scale with how stable the x..x.0 release was, and whether or not any issues directly impacted my projects. If while migrating to a new release I hit something that was causing serious problems I'd just shelve the upgrade until such a time as it makes sense to do so. Clients see the value (and will pay) to keep their web applications on the latest version of the framework, but if it doesn't happen for weeks (or even months) after the initial release there's no problem. |
Thanks @svallis |
Given the following two (simplified) models, configured with the foreign key as
DeleteBehavior.Restrict
:Trying to clear the asset with
product.DownloadAsset = null;
(after loading the data with.Include(x => x.DownloadAsset)
) results in the following error:Clearing with
product.DownloadAssetId = null;
works as expected.Obviously I don't want any entities to be deleted in this case; the only action I expect to occur is for the specified
DownloadAssetId
to be set tonull
.It's kind of difficult for me to test it now, but I'm pretty sure this worked as I expected in 1.1.x.
Further technical details
EF Core version: 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.3
The text was updated successfully, but these errors were encountered: