win7user10 / Laraue.EfCoreTriggers

Library to write triggers in C# with EF.Core
MIT License
112 stars 20 forks source link

Get Entity that inserted, updated or deleted? #35

Closed Ali-YousefiTelori closed 2 years ago

Ali-YousefiTelori commented 2 years ago

Is there a way to get Entity in my c# code that inserted, updated, or deleted? for example, I want to get that entity in the trigger action:

            modelBuilder.Entity<TEntity>()
                .AfterInsert(trigger => trigger.Action(action =>
                {
                    action.OnChange((entity) =>
                    {
                        Console.WriteLine($"Inserted {entity.Id}");
                    });
                }))
                .AfterDelete(trigger => trigger.Action(action =>
                {
                    action.OnChange((entity) =>
                    {
                        Console.WriteLine($"Deleted {entity.Id}");
                    });
                }))
                .AfterUpdate(trigger => trigger.Action(action =>
                {
                    action.OnChange((entity) =>
                    {
                        Console.WriteLine($"Updated {entity.Id}");
                    });
                }));
win7user10 commented 2 years ago

Hi, @Ali-YousefiTelori. There is no way to get entity in C# code, because trigger performs in a DB, this library only creates this trigger.