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
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.
The text was updated successfully, but these errors were encountered:
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.
There are times when we have to define the same relationship in two places (when we use
ApplyConfigurationsFromAssembly
) since the order of applyingIEntityTypeConfiguration
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 beforeOrderConfiguration
.Ideally, the order of applying configuration should not matter as long as the relationship is fully defined at some point.
The text was updated successfully, but these errors were encountered: