-
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
How do I change the default for DeleteBehavior? #4299
Comments
The solution provided in #3815 is correct. If you have not generated FKs on database yet then the solution works fine. But if you already have FK generated in previous migration then as you noticed it generates no migration data due to different bug which got fixed in #3756 (will be shipped in RC2). The bug is Work-around till RC2 release would be set the default behavior to |
The Database I am running against has no existing tables, this is the initial creation of it so no I have not generated any FKs on it yet so something else wrong is happening. Also, why so fast to close this? Maybe I have ran into some bug? |
For the first migration, if the default behavior is changed then generated migration file & script both reflect the changes well. I am able to reproduce empty migration for modifying FK but not for the first one.
|
1: "EntityFramework.Core": "7.0.0-rc1-final", |
I did 3rd step in the same way. After deleting the migrations folder, I ran the migration with solution. But the initial file made has code to generate tables (with Restrict behavior). |
Here is the project, if it is working for you I am sure I am running into some edge case bug or misconfiguration some where. https://drive.google.com/file/d/0BxA-roBz9DmBcmU3clFYNHo1aDg/view?usp=sharing |
Thanks for the project. Can you help out with more details on the steps followed? |
I am not sure where you see "ParentId" at, I don't have any properties named that and the only nullable In16 I have is named "ApprovedByID" is that the one your talking about? But my steps are these: 1: Without the code from your solution I Build Solution What the heck? Now it is working. I swear it was not working before. I don't know maybe something was wrong in VS? I did just have to uninstall Enterprise and install Pro as the IT department installed the wrong edition for my license key. I am sorry, I don't know what has changed. I tried to get the migration to build at least a dozen times using your solution code and it never would till now. For future reference, will the loop always be the way to do this or is there a cleaner way of doing it (like in EF 6) in the works? |
Its alright. Glad it is working now. If you have any further questions let me know. |
For future reference, will the loop always be the way to do this or is there a cleaner way of doing it (like in EF 6) in the works? |
Loop is one way to do this. It was not possible in EF6 but it is in EF7. |
I will take a look at it, thanks again for helping me out. I really appreciate it. |
As mentioned in #3815 the default behavior for DeleteBehavior is CASCADE. In EF6 this could be over ridden with one simple line of code:
modelBuilder.Conventions.Remove();
There seems to be no equivalent inside EF7. Yes, you can type out something like 5 lines of code for every single FK property and explicitly change the behavior but when you have over 100 properties that gets tedious and has a good potential for introducing problems. There was a solution provided in the issue I linked but when I use that then no migration data is generated. I have searched Google and even asked on Stack Overflow but am getting no where. Is there a way to change the default behavior? If not there really should be.
The text was updated successfully, but these errors were encountered: