Updating collection in many side of a one to many releationship

33 Views Asked by At

I am modeling the following many-to-many relationship using Domain Driven Design (DDD).

Many-to-Many relationship in DDD

I am using EF Core for persistence.

The collection on Person is configured like this:

PersonConfigurations.cs

builder.OwnsMany(o => o.PersonOrgIds, ib =>
{
    ib.ToTable("PersonPersonOrgIds");
    ib.WithOwner()
        .HasForeignKey("PersonId");
    ib.HasKey("Id");
    ib.Property(id => id.Value)
        .HasColumnName("PersonOrgId");
});

builder.Metadata.FindNavigation(nameof(Person.PersonOrgIds))!
    .SetPropertyAccessMode(PropertyAccessMode.Field);

Then PersonOrg models the relationship like this:

PersonOrgConfigurations.cs

builder.Property(o => o.PersonId).IsRequired()
    .HasConversion(
        id => id.Value,
        value => PersonId.Create(value));

My question is when I add a PersonOrg how can I reflect that in the collection of Person (and Org).

0

There are 0 best solutions below