Skip to content
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

Inside Deleted trigger all FK properties are null #63

Open
berlaga opened this issue Mar 14, 2022 · 3 comments
Open

Inside Deleted trigger all FK properties are null #63

berlaga opened this issue Mar 14, 2022 · 3 comments

Comments

@berlaga
Copy link

berlaga commented Mar 14, 2022

I'm not sure if this is by design, but when Deleted trigger is fired, if entry.Entity has any foreign key fields, those fields are null.
This makes this handler very limited in it's usability. The only workaround I found is using Deleting trigger. Which is for obvious reasons is not ideal. I'm I missing something?

@NickStrupat
Copy link
Owner

It depends on the relationship defined on those foreign keys. The entity you access through the Deleted event parameters is the same as if you had the entity reference itself after it was deleted.

If you can post a minimal example of the behaviour you're seeing and what you expect to see, that would be a good starting point to finding a solution.

@berlaga
Copy link
Author

berlaga commented Mar 15, 2022

Thanks for your quick reply. Some background: I use triggers to intercept DB events and create JSON messages that being sent to another system for synchronization.
It's possible, that issue is related to On Cascade Delete setting on DB side. The entity is a child entity and when Deleted is fired, the parent entity is already gone. It's a bit hard for me to extract that code. In any case, Deleting trigger does the trick. The only side effect: if deletion actually fails. It's highly unlikely but possible.

@NickStrupat
Copy link
Owner

I think you're right about the cascade delete behaviour. I think you can use the delete failed event to track whether the delete failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants