You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello.
I have repositories with methods that encapsulate the SaveChanges() event declared in a single interface IRepository (Available for anyother by derivation e.g. here below IReferentRepository). This copes properly I guess with the UOW patern. This work perfectly well on my code base and I'm able to save any object of my repo in my db (usign Sqlserver).
Code for : IAfterSaveTrigger
public class UpdateReferent : IAfterSaveTrigger<Measurement>
{
readonly IReferentRepository _ReferentRepository;
public UpdateReferent(IReferentRepository referentRepo)
{
_ReferentRepository = referentRepo;
}
public Task AfterSave(ITriggerContext<Measurement> context, CancellationToken cancellationToken)
{
if (context.ChangeType == ChangeType.Added || context.ChangeType == ChangeType.Modified)
{
var _odm = context.Entity;
if (_odm.Referent != null) //Navigation enabled here
{
var __referent = _ReferentRepository.GetRefById(_odm.Referent.Id);
__referent.LastMeasureDateFromMeasure = _odm.MesureLastUpdateDate;
_ReferentRepository.UpdateEntity(__referent); //Method that updates the Referent
_ReferentRepository.UnitOfWork.SaveChanges(); //The Repo SaveChanges().
}
}
return Task.CompletedTask;
}
}
Code for .AddDbContext declaration in Program.cs
I've declared in my programs.cs the Trigger.
builder.Services.AddDbContext
(options =>
options.UseTriggers(triggerOptions => {
triggerOptions.AddTrigger();
})
);
Issue : AfterSaveTrigger UpdateReferent is never called.
Any tips?
Thanks guys.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello.
I have repositories with methods that encapsulate the SaveChanges() event declared in a single interface IRepository (Available for anyother by derivation e.g. here below IReferentRepository). This copes properly I guess with the UOW patern. This work perfectly well on my code base and I'm able to save any object of my repo in my db (usign Sqlserver).
Code for : IAfterSaveTrigger
Code for .AddDbContext declaration in Program.cs
I've declared in my programs.cs the Trigger.
builder.Services.AddDbContext
(options =>
options.UseTriggers(triggerOptions => {
triggerOptions.AddTrigger();
})
);
Issue : AfterSaveTrigger UpdateReferent is never called.
Any tips?
Thanks guys.
Beta Was this translation helpful? Give feedback.
All reactions