Base solution for your next web application
Open Closed

Audit logging on Dynamic Entity Properties #9786


User avatar
0
devinedon created

Hi,

As a follow up to post #9763, as an alternative option I thought of (but which I can't get to work!) is as follows:

  • Create a new DynamicEntityPropertyClass, which also inherits from IFullAudited, and then enable Entity History for FullAuditedEntities
    • https://docs.aspnetzero.com/en/aspnet-core-mvc/latest/Extending-Existing-Entities
[Audited]
    public class MyDynamicEntityProperty : DynamicEntityProperty, IFullAudited
    {
        public DateTime CreationTime { get; set; }
        public long? CreatorUserId { get; set; }
        public DateTime? LastModificationTime { get; set; }
        public long? LastModifierUserId { get; set; }
        public bool IsDeleted { get; set; }
        public long? DeleterUserId { get; set; }
        public DateTime? DeletionTime { get; set; }
    }

    Configuration.EntityHistory.Selectors.Add(
                new NamedTypeSelector("Abp.FullAuditedEntities", type => typeof(IFullAudited).IsAssignableFrom(type)));

After running the migration to generate the new table with the IFullAudited columns, the relevant columns are not updating e.g. when I add a new entity, the CreationTime and CreatorUserId are still null.

Is the above implementation possible, or am I going down an impossible route?


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    1. Could you also share how do you use MyDynamicEntityProperty in your code ?
    2. Did you try solution offered in https://support.aspnetzero.com/QA/Questions/9763 ? If so, did that work for you ?
  • User Avatar
    0
    devinedon created

    Hi,

    I managed to get this working - thanks for the assistance.