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

> 2 InverseProperties gives: The convention invocations have reached the recursion limit. This is likely an issue in EF Core, please report it. #15738

Closed
Wouter8 opened this issue May 16, 2019 · 3 comments · Fixed by #17514
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Milestone

Comments

@Wouter8
Copy link

Wouter8 commented May 16, 2019

I am trying to setup multiple entities with inheritance. See class definitions (hiding irrelevant properties):

public abstract class PartialAnswer { 
        public int AnswerId { get; set; }
        public virtual Answer Answer { get; set; }
}
public class PartialSortedAnswer : PartialAnswer { }
public class PartialUnsortedAnswer : PartialAnswer { }
public class PartialRepeatingSortedAnswer : PartialSortedAnswer { }
public class PartialRepeatingUnsortedAnswer : PartialUnsortedAnswer { }

public abstract class Answer { }
public class MultipleAnswersUnsorted : Answer {
        public virtual ICollection<Partials.PartialUnsortedAnswer> Answers { get; set; }
}
public class MultipleAnswersSorted : Answer {
        public virtual IEnumerable<Partials.PartialSortedAnswer> Answers { get; set; }
}
public class MultipleAnswersRepeatingUnsorted : Answer {
        public virtual IEnumerable<Partials.PartialRepeatingUnsortedAnswer> Answers { get; set; }
}
public class MultipleAnswersRepeatingSorted : Answer
{
        public virtual IEnumerable<Partials.PartialRepeatingSortedAnswer> Answers { get; set; }
}

When creating a migration with these classes the PartialAnswers table gets 4 columns which are not needed.

  • MultipleAnswersRepeatingUnsortedId
  • MultipleAnswersRepeatingSortedId
  • MultipleAnswersUnsortedId
  • MultipleAnswersSortedId

I want them to all use the column AnswerId which is already part of the abstract class PartialAnswer. I found out that the columns come from the lists in the classed derived from Answer (SO). When adding the InverseProperty annotation I can specify that AnswerId should be used. Sadly I can only do this for 2 out of the 4 (and more coming) classes.

One example for one of the classes using InverseProperty:

public class MultipleAnswersUnsorted : Answer
{
        [InverseProperty("Answer")]
        public virtual ICollection<Partials.PartialUnsortedAnswer> Answers { get; set; }
}

When adding the property to a third class inheriting from Answer the migration fails and gives this error (It doesn't matter which classes I choose. It just limits at 2):

Exception message: The convention invocations have reached the recursion limit. This is likely an issue in EF Core, please report it.
Stack trace:
System.InvalidOperationException: The convention invocations have reached the recursion limit. This is likely an issue in EF Core, please report it.
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Dispose()
   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(TypeIdentity& type, ConfigurationSource configurationSource, Boolean allowOwned, Boolean throwOnQuery)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource, Boolean allowOwned, Boolean throwOnQuery)
   at Microsoft.EntityFrameworkCore.ModelBuilder.Entity[TEntity]()
   at QuizOrganizerAPI.Models.Context.OnModelCreating(ModelBuilder builder) in D:\Documents\Quiz_Organizer\quiz-organizer-api\Models\Context.cs:line 95
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.<GetModel>b__1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_2(IServiceProvider p)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
@ajcvickers
Copy link
Member

@Wouter8 Which release of EF Core are you using?

@Wouter8
Copy link
Author

Wouter8 commented May 16, 2019

Looks like it's under Microsoft.AspNetCore.App: EntityFrameworkCore (2.1.1)

Edit: currently updating, I'll let you know if it fixes the issue in a couple of minutes @ajcvickers.

@Wouter8
Copy link
Author

Wouter8 commented May 16, 2019

@ajcvickers updated to 2.2.0. Getting the same error when adding the InverseProperty to more than 2 of these classes.

@ajcvickers ajcvickers added this to the 3.0.0 milestone May 17, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 30, 2019
@AndriySvyryd AndriySvyryd removed their assignment Aug 30, 2019
@AndriySvyryd AndriySvyryd modified the milestones: Backlog, 3.1.0 Aug 30, 2019
@ajcvickers ajcvickers modified the milestones: 3.1.0, 3.1.0-preview1 Oct 15, 2019
@ajcvickers ajcvickers modified the milestones: 3.1.0-preview1, 3.1.0 Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants