Base solution for your next web application
Open Closed

Entity History EF not detecting update #9987


User avatar
0
elferone created

Angular & ASP.Net Core

ABP version 8.1

ABP framework 5.1.0

When I activate Entity History, It detects when I create and detele an entity. When I update an entity, It doesn't detected.

I follow all the instructions here : https://aspnetboilerplate.com/Pages/Documents/Entity-History && https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Features-Angular-Entity-History

Tryed both configurations :

OR

Is there something missing ?


12 Answer(s)
  • User Avatar
    0
    zony created
    Support Team

    Hi Elferone, In my DEMO project (10.0) it works normally, can you provide more information? For example, sample code or sample project.

  • User Avatar
    0
    elferone created

    I tryed with two Entities :

    The first one is one of mine :

    The second one is abp role entity (this code is provided by asp.net zero, it hasn't been touched) :

    Both didn't work.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @elferone,

    Could you share the entity you have this problem with ?

    Thanks,

  • User Avatar
    0
    elferone created

    Those are my entities :

    OR

  • User Avatar
    0
    zony created
    Support Team

    Hi elferone, I tested it based on the entity you provided, and it also works. Test ApplicationService:

    public class TestAppService : QADemoDemoAppServiceBase
    {
        private readonly IRepository<Role> _roleRepository;
        private readonly IRepository<MemberActivityEntity> _memberActivityEntityRepository;
    
        public TestAppService(IRepository<Role> roleRepository,
            IRepository<MemberActivityEntity> memberActivityEntityRepository)
        {
            _roleRepository = roleRepository;
            _memberActivityEntityRepository = memberActivityEntityRepository;
        }
    
        [UnitOfWork]
        public async Task<string> TestMethod()
        {
            var roleList = await _roleRepository.GetAllListAsync();
            var role = roleList.First(); // default admin role
            role.DisplayName = "ADMIN-2";
    
            await _roleRepository.UpdateAsync(role);
    
            var activityEntities = await _memberActivityEntityRepository.GetAllListAsync();
            var act = activityEntities.First(); // custom entity
            act.Description = "New Desc";
    
            await _memberActivityEntityRepository.UpdateAsync(act);
    
            await CurrentUnitOfWork.SaveChangesAsync();
            return "Success";
        }
    }
    

    Custom Entity:

    public class MemberActivityEntity : FullAuditedEntity<int>
    {
        [Column("MemberActivityId")]
        public override int Id { get; set; }
    
        [Required]
        [StringLength(64)]
        public string Code { get; set; }
    
        [Required]
        [StringLength(1024)]
        public string Description { get; set; }
    
        [Required]
        public bool UseSpouseInfo { get; set; }
    
        [Required]
        public bool IsActiveForInsurance { get; set; }
    
        [Required]
        public bool IsActive { get; set; }
    
        [Required]
        public bool IsRetired { get; set; }
    
        public byte? PeriodCount { get; set; }
    
        [Required]
        public bool IsArchived { get; set; }
    }
    

    Module configuration:

    Configuration.EntityHistory.IsEnabled = true;
    Configuration.EntityHistory.Selectors.Add(new NamedTypeSelector(
        "Abp.FullAuditedEntities",
        type => typeof(IFullAudited).IsAssignableFrom(type)
    ));
    
  • User Avatar
    0
    elferone created

    Is is necessary to use : await CurrentUnitOfWork.SaveChangesAsync(); ?

  • User Avatar
    0
    elferone created

    I went and got an empty project. I tested on it and the update was working. When I activate lazy loading it stopped working.

    So the source of the problem was the lazy loading. Now I have to find a way to make it work together.

    Does anybody faced the same problem ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @elferone

    Thank you for sharing the solution. Could you share how did you enable lazy loading ?

  • User Avatar
    0
    elferone created

    Hi,

    I went into the DbContextConfigurer and added both lines :

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @elferone,

    Could you create an issue on https://github.com/aspnetboilerplate/aspnetboilerplate ? We will take a deep look at into this for the next version of ABP.

  • User Avatar
    0
    elferone created

    Hi,

    This is the link of the issue created :

    https://github.com/aspnetboilerplate/aspnetboilerplate/issues/5996

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @elferone

    I have added this issue to 6.3 milestone. We will work on it soon.