-
Notifications
You must be signed in to change notification settings - Fork 60
WillCascadeOnDelete not working with EF Core #22
Comments
Thanks for the bug report. I'm looking into this; cascade delete support has always been a bit problematic and since you're bringing it up, it's a good time to review it again. You've got a good start on the fix. There's a bit more to do, since really the flag deals with the principal and dependent ends of the relationship, and that's not exposed nicely in the designer. So I'll do a bit more with the design surface as well as the T4. If all goes right, this fix should be out in v1.2.6.7 |
Thanks for taking care of this. Just as a additional remark/question: |
The concept is to propagate deletion to the other end of the association depending on which end is deleted. So, if While technically we're deleting associations, that's not the common way to consider object deletion. Rather, it's just that ... object deletion, which is why there cascade behaviors are defined on the classes that are at the ends of the associations. That being said, EF's cascade delete behavior is currently only defined for removing dependent objects, not the other way around. That's a blemish in the designer, and I'm planning to refine what's displayed in the property editor to make that clear, with parallel changes in code generation. Good article re: cascade delete in EF6 (with some discussion of EFCore) at https://weblogs.asp.net/ricardoperes/entity-framework-pitfalls-cascade-deletes Hope that makes sense. |
Fixed in v1.2.6.7. Took what you offered and added a few more enhancements to the property editor so that it was clearer what was going to happen in the generated code. And I'll be adding more documentation on this -- it's currently extremely wimpy in this area -- as soon as I have a moment. Thanks! |
- An entity's concurrency token property is no longer a required parameter in its constructor (#24) - Simplified cascade delete settings in property editor for associations - Fixed bad code generation in EFCore for cascade delete overrides (#22) - Missing files when generating code for .NET Core projects fixed - Tightened up and swatted some bugs in INotifyPropertyChanged handling. Added documentation to doc site for this feature (following up on #23) - Ensured multiline editing was available in property window for those properties that made sense
Hi
When I define relations between entities and set End 1 on delete resp. End 2 on delete to Cascade or None the EFDesigner creates a .WillCascadeOnDelete(true/false). This did not compile on my system. AFIK WillCascadeOnDelete does not exist for EF core (it does in EF6) and OnDelete(DeleteBehavior) has to be used for EF Core.
Replacing the code to generate WillCascadeOnDelete for the for undirectionalassociations with
and for the bidirectionalassociations with
in the EFCoreDesigner.ttinclude seems to fix the problem. Not sure if this would be valid for all use cases.
Small side note:
I'm not sure if I got this right, but for Bidirectionalassociations the docu on End 1 on delete resp. End 2 on delete says How to handle objects on this end if the object on the other end is deleted. However the T4 files for EF core, seem to handle this more like How to handle objects on the other end if the object on this end is deleted.
The text was updated successfully, but these errors were encountered: