Hello,
My entity have value object like below
public class PersonEmailConfiguration : IEntityTypeConfiguration<PersonEmail> { public void Configure(EntityTypeBuilder<PersonEmail> builder) { builder.ToTable("PersonEmails", SchemaNames.Person);
builder.HasIndex(p => new { p.TenantId, p.PersonId });
builder.Property(p => p.Id).ValueGeneratedNever();
builder.Property(p => p.EmailTypeCode).IsRequired();
builder.Property(p => p.IsPrimary).IsRequired();
builder
.HasOne(p => p.Person)
.WithMany(p => p.Emails)
.HasForeignKey(p => p.PersonId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasOne(p => p.EmailType)
.WithMany()
.HasForeignKey(p => new { p.EmailTypeCode, p.TenantId })
.HasPrincipalKey(p => new { p.Code, p.TenantId })
.OnDelete(DeleteBehavior.NoAction);
builder.OwnsOne(p => p.Email, p =>
{
p.Property(c => c.Address).IsRequired().HasColumnName("Email");
});
}
}
Its value object
public class Email : ValueObject
{
public string Address { get; }
private Email() { }
public Email(string address)
{
if (!address.Contains("@")) throw new Exception("Email is invalid");
Address = address;
}
protected override IEnumerable<object> GetAtomicValues()
{
yield return Address;
}
}
Problem is, if i update PersonEmail => Email => Address field predefined events not trigger auto I have to mark entity updated for fix problem with _personEmailRepository.UpdateAsync(email); Maybe this subject related about that => https://stackoverflow.com/questions/51416721/ef-core-owned-property-state-propagation-to-parent-entity
10 Answer(s)
-
0
Hi,
Actually AspNet Boilerplate also uses a similar approach, see https://github.com/aspnetboilerplate/aspnetboilerplate/pull/4080/files.
You can override ApplyAbpConcepts method of your DbContext (here) and see if
entry.CheckOwnedEntityChange()
returns true or false. -
0
Thank you, will it fix next version of boilerplate?
-
0
Hi,
Did you find an error ? Did
entry.CheckOwnedEntityChange()
returned false ? -
0
I didnt try yet, just i wonder why pull request waiting since 2018 :)
-
0
Hi,
The PR I have shared is already merged.
-
0
Hi,
I didnt check state but, im sure EntityChangingEventData not trigger if i update value object
-
0
hi @murat.yuceer
Did you find an error ? Did entry.CheckOwnedEntityChange() returned false ?
Can you check it out?
-
0
Hi, I checked, it was return false but i changed my code and its worked
Before my code was like below
public void SetPhone(Phone phone) { Check.NotNull(phone, nameof(phone)); if (phone.ValueEquals(Phone)) return; Phone = phone; }
I changed like below and it worked
public void SetPhone(Phone phone) { Check.NotNull(phone, nameof(phone)); if (phone.ValueEquals(Phone)) return; Phone.PhoneNumber = phone.PhoneNumber; Phone.CountryCode = phone.CountryCode; Phone.ExtensionNumber = phone.ExtensionNumber; }
-
0
Maybe ef is tracking the reference of the entity object.
In short, your problem is solved. Right?
-
0
Yes, thanks for help