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.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
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; } }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi williepieterse
You want to add new properties EmployeeId and EmployeeFk to the
EntityChangeSettable, right? TheEntityChangeSetclass inherits theIExtendableObjectinterface.IExtendableObjectalso adds theExtensionDataproperty to theEntityChangeSetproperties.ExtensionDatais in string structure and you can store json information here. If you want to change the value in some cases. Check out this documentIEntityChangeSetReasonProviderallows you to change specific field.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Perfect, sorry I missed the EntityHistory looking too deep into AuditingStore.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
We are glad you solved your problem. Enjoy your work
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
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
}
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)