Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of relationship vs navigation configuration when using ApplyConfigurationsFromAssembly #30068

Closed
vflame opened this issue Jan 14, 2023 · 4 comments

Comments

@vflame
Copy link

vflame commented Jan 14, 2023

There are times when we have to define the same relationship in two places (when we use ApplyConfigurationsFromAssembly) since the order of applying IEntityTypeConfiguration matters.

When we explicitly control the order of configuration, it works as expected (e.g., explicitly configured in ApplicationDbContext.cs OnModelCreating).

But if we using something like the following two config classes, the order in which the configuration is applied can cause the navigation not found exception to be thrown if PaymentConfiguration was applied before OrderConfiguration.

public class PaymentConfiguration : IEntityTypeConfiguration<Payment>
{
    public void Configure(EntityTypeBuilder<Payment> builder)
    {
        //navigation not found exception thrown
        builder.Navigation("_order").AutoInclude();
    }
}

public class OrderConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
       builder.HasMany<Payment>("_payments").WithOne("_order");
    }
}

Ideally, the order of applying configuration should not matter as long as the relationship is fully defined at some point.

@ajcvickers
Copy link
Contributor

@vflame Why not define the relationship in PaymentConfiguration?

builder.HasOne<Order>("_order").WithMany("_payments");
builder.Navigation("_order").AutoInclude();

@vflame
Copy link
Author

vflame commented Jan 14, 2023

@vflame Why not define the relationship in PaymentConfiguration?

builder.HasOne<Order>("_order").WithMany("_payments");
builder.Navigation("_order").AutoInclude();

That's what we resorted to doing. Just wanted to point out this behavior and how order of applying configs matters when ideally it shouldn't. (e.g., all navigations configs are applied after relationship configs are applied) after scanning all assemblies.

@ajcvickers
Copy link
Contributor

@AndriySvyryd I can't find an issue for ordering the configurations.

@AndriySvyryd
Copy link
Member

Duplicate of #22035

@AndriySvyryd AndriySvyryd marked this as a duplicate of #22035 Jan 19, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants