Hi oguzhanagir, thank you for the answer and for putting me on the right way.
I preferred to extending EntityHistoryStore
using a more generic method, because the entity HomeAddress
is owned by different entities and I had the same problem with other owned entities. So this is my method:
public override Task SaveAsync(EntityChangeSet changeSet)
{
foreach (var change in changeSet.EntityChanges)
{
EntityEntry entityEntry = (EntityEntry)change.EntityEntry;
if (entityEntry.Metadata.IsOwned())
{
var ownership = entityEntry.Metadata.FindOwnership();
if (ownership != null)
{
change.EntityTypeFullName = ownership.PrincipalEntityType.Name;
}
}
}
return base.SaveAsync(changeSet);
}
It seems to work as I need. Thank you
I have an entity Employee with owned entity Address
public sealed class Employee : FullAuditedEntity, IMustHaveTenant
{
...
public Address HomeAddress { get; private set; }
...
}
public class Address : ValueObject
{
public int? MunicipalityId { get; private set; }
public Municipality? Municipality { get; private set; }
[MaxLength(GeographyConsts.MaxAddressLineLength)]
public string? AddressLine { get; private set; } = string.Empty;
public int? Number { get; private set; }
...
}
public class EmployeeConfiguration : IEntityTypeConfiguration<Employee>
{
public void Configure(EntityTypeBuilder<Employee> builder)
{
builder.ToTable("Employees");
builder.OwnsOne(x => x.HomeAddress);
}
}
In EntityHistory the changes of Employee HomeAddress owned entity are correctly tracked but the EntityTypeFullName is Address
not Employee
so it's difficult to get a list of all the changes about an Employee.
Am I missing something?