title: EF - Unable to determine the relationship
body: <p>I'm making a fantasy game application. Right now a team can have multiple players, but also multiple users (like league). When i try to add the a collection to the team table, i get the following error <strong><em>(see below)</em></strong>. 
  I tried to find the solution online and it seems that this problem is causes by a many to many relationship. However, i don't see how that is possible. A team can have many users, but a user can only have one team. 
  The solution was to create a join table, but why would i create a column on each table to point to a join table that contains the data, when i could just have the column on each table join to the other table? 
  Does anyone know what is causing this error and how to fix it?</p>
  
  <pre><code>System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'Team.Manager' of type 'User'. Either manually configure the relationship, or ignore this property from the model.    at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
      at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)
     at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
      at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
      at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
      at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value() 
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceProvider.&lt;&gt;c__DisplayClass16_0.&lt;RealizeService&gt;b__0(ServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceProvider.&lt;&gt;c__DisplayClass16_0.&lt;RealizeService&gt;b__0(ServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
     at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
      at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action`1 reporter)
      at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0()
      at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) 
     at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
   Unable to determine the relationship represented by navigation property 'Team.Manager' of type 'User'. Either manually configure the relationship, or ignore this property from the model. 
  </code></pre>
  
  <p>Team.cs</p>
  
  <pre><code>public class Team
  {
      [Key]
      public int ID { get; set; }
      public int ManagerID { get; set; }
      public string Name { get; set; }
  
      [ForeignKey("ManagerID")]
      public virtual User Manager { get; set; }
      public virtual ICollection&lt;Player&gt; Players { get; set; }
      // Unable to determine the relationship represented by navigation property 'Team.Manager' of type 'User'
      public virtual ICollection&lt;User&gt; TeamMebers { get; set; }
  
  
      public Team()
      {
          TeamMebers = new List&lt;User&gt;();
          Players = new List&lt;Player&gt;();
      }
  }
  </code></pre>
  
  <p>User.cs</p>
  
  <pre><code>public class User
  {
      [Key]
      public int ID { get; set; }
      public int? TeamID { get; set; }
      public string UserName { get; set; }
      public string Name { get; set; }
      public bool ShowAsPm { get; set; }
      public string Deactiviated { get; set; }
  
      [ForeignKey("TeamID")]
      public virtual Team Team { get; set; }
      // How many hours they played 
      public virtual ICollection&lt;Log&gt; Hours { get; set; }
  
      public User()
      {
          Hours = new List&lt;Log&gt;();
      }
  }
  </code></pre>
  
  <p>Log.cs</p>
  
  <pre><code>public class Log
  {
      [Key]
      public int ID { get; set; }
      public int? GameID { get; set; }
      public int? ResultID { get; set; }
      public int? UserID { get; set; }
  
      public string SmNumber { get; set; }
      public decimal? Duration { get; set; }
      public DateTime LogDate { get; set; }
  
      [ForeignKey("GameID")]
      public virtual Game Game { get; set; }
      [ForeignKey("ResultID")]
      public virtual GameResult Result { get; set; }
      [ForeignKey("UserID")]
      public virtual User User { get; set; }
  
      public Log() { }
  }
  </code></pre>
  
  <p>Context.cs</p>
  
  <pre><code>protected override void OnModelCreating(ModelBuilder builder)
  {
       //builder.Entity&lt;Team&gt;().HasMany(t =&gt; t.TeamMebers).WithOne(u =&gt; u.Team).HasForeignKey(u =&gt; u.ID);
      //builder.Entity&lt;User&gt;().HasOne(u =&gt; u.Team).WithMany(t =&gt; t.TeamMebers).HasForeignKey(t =&gt; t.ID);
      builder.Entity&lt;Team&gt;().ToTable("Teams");
      builder.Entity&lt;User&gt;().ToTable("Users");
      builder.Entity&lt;Log&gt;().ToTable("Logs");
  }
  </code></pre>
  
  <p><strong>Update</strong> </p>
  
  <pre><code>protected override void OnModelCreating(ModelBuilder builder)
  {
      builder.Entity&lt;Team&gt;().ToTable("Teams");
      builder.Entity&lt;User&gt;().ToTable("Users");
      builder.Entity&lt;User&gt;().HasOne(u =&gt; u.Team).WithMany(u =&gt; u.TeamMebers);
      builder.Entity&lt;Log&gt;().ToTable("Logs");
  }
  </code></pre>
  
  <p>Exception </p>
  
  <pre><code>System.InvalidOperationException: The current CSharpHelper cannot scaffold literals of type 'System.Collections.Immutable.ImmutableSortedDictionary`2[System.Reflection.PropertyInfo,System.Type]'. Configure your services to use one that can.    at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpHelper.UnknownLiteral(Object value)
      at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateAnnotation(IAnnotation annotation, IndentedStringBuilder stringBuilder)
     at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypeAnnotations(IEntityType entityType, IndentedStringBuilder stringBuilder)
     at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder)
      at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList`1 entityTypes, IndentedStringBuilder stringBuilder) 
     at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.Generate(String builderName, IModel model, IndentedStringBuilder stringBuilder)
     at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMetadata(String migrationNamespace, Type contextType, String migrationName, String migrationId, IModel targetModel)
     at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace)
      at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
      at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action`1 reporter) 
      at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0()
      at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) 
     at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
   The current CSharpHelper cannot scaffold literals of type 'System.Collections.Immutable.ImmutableSortedDictionary`2[System.Reflection.PropertyInfo,System.Type]'. Configure your services to use one that can. 
  </code></pre>