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)
-
0
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.
-
0
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; } } -
0
Hi williepieterse
You want to add new properties EmployeeId and EmployeeFk to the
EntityChangeSet
table, right? TheEntityChangeSet
class inherits theIExtendableObject
interface.IExtendableObject
also adds theExtensionData
property to theEntityChangeSet
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 documentIEntityChangeSetReasonProvider
allows you to change specific field. -
0
Perfect, sorry I missed the EntityHistory looking too deep into AuditingStore.
-
0
We are glad you solved your problem. Enjoy your work
-
0
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
}