Laraue.EfCoreTriggers
Laraue.EfCoreTriggers copied to clipboard
How i can get multiple AfterUpdate
Hello Thankyou for this wonderful package, i wondering if its possible to create a multiple AfterUpdate with diffrents Names?
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
.
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.
The syntax for multiple actions is
modelBuilder.Entity<Transaction>()
.AfterUpdate(trigger => trigger
.Action(action => action.Update(...)
.Action(action => action.Update(...));
@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.
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.