Laraue.EfCoreTriggers
Laraue.EfCoreTriggers copied to clipboard
Condition check if it is the last reference in after delete
Is it possible to configure a trigger like this one with this library?
What i'm trying to achieve is to delete one side of a many to many relationship table if this is the last row pointing to it
Tables: -Persons -PersonProducts -Products
i want the product to be deleted when the last PersonProduct referencing it is deleted
builder
.AfterDelete(trigger => trigger
.Action(action => action
.Condition(pp => pp.Product!.PersonProducts.Count() == 1)
.Delete<Product>((personProduct, product) => personProduct.ProductId == product.Id)
)
);