Open Closed

Change-in-Related-Entity-Does-Not-Trigger-Change-Event-for-Parent-Entity-in-DbContext #8386


User avatar
0
mohammedalqaisi created
  • ABP Framework version: v8.3.1
  • UI Type: Angular
  • Database System: EF Core ( MySQL)
  • Auth Server Separated (for Angular): yes
  • Steps to reproduce the issue:

Given the following entity configurations:

builder.Entity<Employee>(b =>
{
    b.ConfigureByConvention();
	b.HasOne(x => x.Course).WithMany().HasForeignKey(x => x.CourseId);
});

builder.Entity< Course >(b =>
{

});

When the CourseId associated with an Employee is changed, the PublishEventsForTrackedEntity feature in the DbContext does not trigger a change event for the Employee entity, even though the Employee entity is effectively modified.

This behavior appears to be inconsistent, as changes to the Employee should ideally trigger the corresponding event.


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    you can try

    Configure<AbpEntityChangeOptions>(options => 
    {
        options.PublishEntityUpdatedEventWhenNavigationChanges = true;
    })
    

    https://abp.io/docs/latest/framework/infrastructure/event-bus/local#abpentitychangeoptions

  • User Avatar
    0
    mohammedalqaisi created

    Hi,

    you can try

    Configure<AbpEntityChangeOptions>(options =>  
    { 
        options.PublishEntityUpdatedEventWhenNavigationChanges = true; 
    }) 
    

    https://abp.io/docs/latest/framework/infrastructure/event-bus/local#abpentitychangeoptions

    If an Employee is linked to a Course through the CourseId property, for example, an employee initially assigned to a "Math" course with a CourseId of 856, and then the course is changed to "Physics" with a CourseId of 499, the CourseId property in the Employee entity will be updated accordingly. However, as written in the code (referenced in Section 1), this change is being skipped and does not proceed to Section 2 for further handling.

    public class Employee
    {
        public int Id { get; set; }         
        public string Name { get; set; }     
        public int CourseId { get; set; }    // Foreign Key for Course
    }
    
    
    public class Course
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    
    

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share a test project with these entities?

    I will download it and try to check the event.

    Thanks

    liming.ma@volosoft.com

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09