You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Order of relationship vs navigation configuration when using ApplyConfigurationsFromAssembly #30068
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.
Reacted by Vaggelis Diatsigkos, Grigoris Adamopoulos and Michael W Powell
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.
Reacted by Vaggelis Diatsigkos, Grigoris Adamopoulos and Michael W Powell
Activity
ajcvickers commentedon Jan 14, 2023
@vflame Why not define the relationship in
PaymentConfiguration?vflame commentedon Jan 14, 2023
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 commentedon Jan 19, 2023
@AndriySvyryd I can't find an issue for ordering the configurations.
AndriySvyryd commentedon Jan 19, 2023
Duplicate of #22035