Base solution for your next web application
Open Closed

Extending EntityChangeSet #12273


User avatar
0
williepieterse created

I need to extend EntityChangeSet with a new property Guid? EmployeeID, We created a IMustHaveEmployee interface where Entities that relates to Employee Implement this interface

We need to include the EmployeeId for any Entity that implements the Interface IMustHaveEmployee i.e. EmployeePhoneNumber Entity.

The reason for this is to lookup any changes made to a specific Employee in the Entity Changelog, similar to searching for any User specific changes on the Entity Changelog

Problem: It is easy the extend the entity and UI etc, but how can I extend the Entity Changelog to also save the EmployeeId for entities that implements IMustHaveEmployee


6 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @williepieterse

    The EntityChangeSet entity inherits the IExtendableObject interface, you will add Custom data using the property from this interface. You can review this document for detailed information.

  • User Avatar
    0
    williepieterse created

    Hi, I think you misunderstood my question.

    I understand that I might need to change from extending the entity to using IExtendableObject interface.

    Where can I set the EmployeeId during Entity Change auditing process to also store the EmployeeId if the following is true:

    var employeeRelatedEntity = thisAuditedEntity as IMustHaveEmployee; if (employeeRelatedEntity != null) { entityChangeSet.EmployeeId = employeeRelatedEntity.EmployeeId; }

    and the interface:

    public interface IMustHaveEmployee {
    public Guid EmployeeId { get; set; } [ForeignKey("EmployeeId")] public Employee EmployeeFk { get; set; } }

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi williepieterse

    You want to add new properties EmployeeId and EmployeeFk to the EntityChangeSet table, right? The EntityChangeSet class inherits the IExtendableObject interface. IExtendableObject also adds the ExtensionData property to the EntityChangeSet properties. ExtensionData is in string structure and you can store json information here. If you want to change the value in some cases. Check out this document IEntityChangeSetReasonProvider allows you to change specific field.

  • User Avatar
    0
    williepieterse created

    Perfect, sorry I missed the EntityHistory looking too deep into AuditingStore.

  • User Avatar
    0
    oguzhanagir created
    Support Team

    We are glad you solved your problem. Enjoy your work

  • User Avatar
    0
    williepieterse created

    Thankyou I ended up implementing my own version of IEntityHistoryHelper and extending the EntityChange with a EmployeeId. Then in the CreateEntityChange added the following check:

    Guid? employeeid = null;

    IMustHaveEmployee testMustHaveEmployee = entityEntry.Entity as IMustHaveEmployee; if (testMustHaveEmployee != null) { employeeid = testMustHaveEmployee.EmployeeId; }

    return new myEntityChange { ChangeType = entityChangeType, EntityEntry = entityEntry, EntityId = entityId, EntityTypeFullName = fullName, TenantId = base.AbpSession.TenantId, EmployeeId = employeeid

    }