win7user10 / Laraue.EfCoreTriggers

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

NotImplementedException using AfterUpdate trigger #25

Closed StickNitro closed 2 years ago

StickNitro commented 2 years ago

I have the following which I took from examples I have seen

    builder.AfterUpdate(trigger => trigger
        .Action(action => action
            .Insert<CalendarAuditEntity>(
                (oldUpdatedEntity, newUpdatedEntity) => oldUpdatedEntity.ToCalendarAudit()
            )));

When I run this through a IEntityTypeConfiguration instance I am getting a NotImplementedException and for the life of me I cannot see what is wrong with this. I have a base table builder is the Calendar table and on update I want to insert the updated record into the CalendarAudit table.

NOTE: oldUpdatedEntity.ToCalendarAudit() returns a new CalendarAuditEntity instance.

Any help would be appreciated!

DotNet Core -> 6. EF Core -> 6. Laraue.EfCoreTriggers -> 6.1.*

win7user10 commented 2 years ago

Hi, this library translates C# code into SQL trigger. After inserting CalendarAuditEntity should be executed content of ToCalendarAudit() method, which is not available when the trigger is fired. But for insert an entity based on the entity before the update you can use a syntax like


(oldUpdatedEntity, newUpdatedEntity) => new CalendarAuditEntity
{
  Field1 = oldUpdatedEntity.Field1,
  Field2 = oldUpdatedEntity.Field2
}