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

How can I set onUpdate constraint globally? #12134

Closed
AuthorProxy opened this issue May 24, 2018 · 3 comments
Closed

How can I set onUpdate constraint globally? #12134

AuthorProxy opened this issue May 24, 2018 · 3 comments

Comments

@AuthorProxy
Copy link

AuthorProxy commented May 24, 2018

Currently, I can globally set onDelete constraint via DeleteBehavior

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()).Where(r => r.DeleteBehavior != DeleteBehavior.Restrict))
            {
                relationship.DeleteBehavior = DeleteBehavior.Restrict;
            }

            FixSnakeCaseNames(modelBuilder);
        }

How I can make something similar for OnUpdate constraint via attributes, conventions or|and globally like the sample upper

@ajcvickers
Copy link
Member

@AuthorProxy The code you show is essentially the recommended way to do this. The convention system does not yet have public API (#214) and is designed more for providers than applications. That being said, once the API is public you should be able to use it to process a custom attribute, but it's not clear that it would be better than what you are already doing.

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label May 25, 2018
@AuthorProxy
Copy link
Author

AuthorProxy commented May 26, 2018

@ajcvickers I am sorry, maybe I have asked not clearly, and should duplicate question at the body, the question is how to set OnUpdate constraint at EF Core 2+

@ajcvickers
Copy link
Member

@AuthorProxy Sorry about that. Cascading updates are not yet supported by EF--this is being tracked by #10551. You'll need to add SQL to the Migration if you want to create cascading updates manually, but keep in mind that EF will not be aware of them and this could result in tracked entities getting out of sync with those in the database.

@ajcvickers ajcvickers added closed-duplicate and removed closed-no-further-action The issue is closed and no further action is planned. labels May 29, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants