I have two tables with relation:
modelBuilder.Entity<User>()
.HasOptional(u => u.Subscription)
.WithMany();
how can I remove relation?
I want remove Subscription but leave all users.
If I remove subscription EF throw exception:
"The DELETE statement conflicted with the REFERENCE constraint
\"FK_Users_Subscriptions_Subscription_Id\".
The conflict occurred in database \"db\",table \"dbo.Users\",
column 'Subscription_Id'.\r\nThe statement has been terminated.
And I want have access from user to subscription.
When you delete a subscription you must ensure that the subscription references of all users with that subscription are set to null, otherwise you violate a foreign key constraint in the database. I think, it is enough to load the users with the subscription to delete into the context. EF will fix the relationships automatically: