Base solution for your next web application
Open Closed

Entity History Tracking #4931


User avatar
0
sunilkosuri created

Hello,

I have configured entity history tracking in my module (where I created my own entities):

public class EPASSCoreModule : AbpModule { public override void PreInitialize() { //workaround for issue: <a class="postlink" href="https://github.com/aspnet/EntityFrameworkCore/issues/9825">https://github.com/aspnet/EntityFramewo ... ssues/9825</a> //related github issue: <a class="postlink" href="https://github.com/aspnet/EntityFrameworkCore/issues/10407">https://github.com/aspnet/EntityFramewo ... sues/10407</a> AppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue9825", true); Configuration.EntityHistory.IsEnabled = true; Configuration.Auditing.IsEnabledForAnonymousUsers = true; ../ }

I then changed a property of an entity through the ReST service and it successfully changed it in the database. However, I don't see any database entries in any of the following 3 tables:

[dbo].[AbpEntityChanges] [dbo].[AbpEntityChangeSets] [dbo].[AbpEntityPropertyChanges]

As an example, my entities are configured as follows:

namespace RightHire.EPASS.Model { [Table("Buildings")] public class Building : FullAuditedEntity {

    [Column("Building_Id")]
    public override int Id { get; set; }

	public virtual string Building_Name { get; set; }
	
	public virtual string Building_Number { get; set; }

    [ForeignKey("Location_City_State")]
    public virtual int? Location_City_State_Id { get; set; }
    public virtual Location_City_State Location_City_State { get; set; } // Add this navigation property

    public virtual bool Active_Indicator { get; set; }
	
	public virtual string Facility_Number { get; set; }
	
	public virtual string Facility_Name { get; set; }
	
	public virtual bool Display_Global { get; set; }
	

}

}

What am I missing?


5 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    No entities are automatically tracked by default. You should configure entities either by using the startup configuration or via attributes. Try adding [Audited] attribute to your entity.

    [Audited]
            [Table("Buildings")]
            public class Building : FullAuditedEntity
            {
    
                [Column("Building_Id")]
                public override int Id { get; set; }
    
                public virtual string Building_Name { get; set; }
    
                public virtual string Building_Number { get; set; }
    
                [ForeignKey("Location_City_State")]
                public virtual int? Location_City_State_Id { get; set; }
                public virtual Location_City_State Location_City_State { get; set; } // Add this navigation property
    
                public virtual bool Active_Indicator { get; set; }
    
                public virtual string Facility_Number { get; set; }
    
                public virtual string Facility_Name { get; set; }
    
                public virtual bool Display_Global { get; set; }
    
    
            }
    

    see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Entity-History#enable-disable-by-attributes">https://aspnetboilerplate.com/Pages/Doc ... attributes</a>

  • User Avatar
    0
    sunilkosuri created

    I did configure it in my module. Please see the code I posted. However, it did not work.

  • User Avatar
    0
    aaron created
    Support Team

    The code you posted shows no configuration by selectors or attributes.

  • User Avatar
    0
    sunilkosuri created

    So, it’s not enough to to do the following?

    Configuration.EntityHistory.IsEnabled = true;

    I specified the above in th code I posted.

  • User Avatar
    0
    aaron created
    Support Team

    Indeed.

    <cite>alper: </cite> No entities are automatically tracked by default. You should configure entities either by using the startup configuration (selectors) or via attributes.