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 i can get multiple AfterUpdate #48

Open
sallamia opened this issue May 26, 2022 · 5 comments
Open

How i can get multiple AfterUpdate #48

sallamia opened this issue May 26, 2022 · 5 comments

Comments

@sallamia
Copy link

Hello
Thankyou for this wonderful package, i wondering if its possible to create a multiple AfterUpdate with diffrents Names?

@kjkrum
Copy link

kjkrum commented Jul 18, 2022

I've been poking around in the lib for my own purposes and may have a solution for this. The Name property is virtual, so perhaps you could extend one of the trigger types and override it. The migration builder only looks for triggers whose name starts with Constants.AnnotationKey, but you should be able to customize the rest of the name. I don't think you can provide a trigger factory to create triggers of your own type, so you'd have to get the IMutableEntity from the EF model builder, create an instance of your trigger, and add it directly. I also noticed that ITriggerVisitor.ConvertTriggerAnnotationsToSql operates on ITrigger, so in theory you could implement that entire interface yourself. Name would still have to start with Constants.AnnotationKey.

@MacyF
Copy link

MacyF commented Jul 21, 2022

I'm facing the same issue, and the suggestion by @kjkrum was great, but for those who does not have much experience with extension creation this can be "painful" and make them leave this package aside.

So @win7user10 I think that it would be nice if you refactor the trigger creation annotation to accept an optional name, so in the trigger class would have something like:
public virtual string Name => $"{Constants.AnnotationKey}_{TriggerTime}_{TriggerEvent}_{typeof(TTriggerEntity).Name}_{AdditionalName}".ToUpper();

It would be an expected behavior since when we create triggers with raw SQL we can name them as we want, but with your convention we could have some consistency.

@win7user10
Copy link
Owner

The syntax for multiple actions is

modelBuilder.Entity<Transaction>()
    .AfterUpdate(trigger => trigger
        .Action(action => action.Update(...)
        .Action(action => action.Update(...));

@win7user10
Copy link
Owner

@MacyF, I should see the source. As I remember, there was a problem with removing the trigger in the Down() method of migration when the trigger name was not a constant. But there were a lot of modifications since that time, and maybe it is possible now.

@MacyF
Copy link

MacyF commented Aug 1, 2022

The syntax for multiple actions is

modelBuilder.Entity<Transaction>()
    .AfterUpdate(trigger => trigger
        .Action(action => action.Update(...)
        .Action(action => action.Update(...));

Thanks you for the tip, but with some help I'm managed to the the job through raw sql.
And I've tried this approach back them I was creating the triggers and it does not work as I wanted, but maybe in other cenario it could feat the needs.

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

4 participants