title: An unhandled exception occurred while trying to save new data
body: <p>I'm trying to save the changes changes for a question and answer project I am creating. I can't save Tags because it returns an exception whenever I query if the data already exists.</p>
  
  <pre><code> public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options) : base(options)
          {
          }
  
      public DbSet&lt;ApplicationUser&gt; ApplicationUsers { get; set; }
      public DbSet&lt;Question&gt; Questions { get; set; }
      public DbSet&lt;Tag&gt; Tags { get; set; }
      public DbSet&lt;QuestionTag&gt; QuestionTags { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
  
          modelBuilder.Entity&lt;QuestionTag&gt;()
                      .HasKey(t =&gt; new { t.QuestionID, t.TagID });
  
          modelBuilder.Entity&lt;QuestionTag&gt;()
              .HasOne(qt =&gt; qt.Question)
              .WithMany(q =&gt; q.QuestionTags)
              .HasForeignKey(qt =&gt; qt.QuestionID);
  
          modelBuilder.Entity&lt;QuestionTag&gt;()
              .HasOne(qt =&gt; qt.Tag)
              .WithMany(t =&gt; t.QuestionTags)
              .HasForeignKey(qt =&gt; qt.TagID);
  }
  </code></pre>
  
  <p>Here is the code I use to Parse new Data while querying if the Tags already exist.</p>
  
  <pre><code>public List&lt;QuestionTag&gt; ParseTags(string tags)
          {
              var tagList = tags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
          var questionTags = new List&lt;QuestionTag&gt;();
          var anyNewTags = false;
  
          foreach (var tag in tagList)
          {
              var tagExists = _context.Tags.Where(x =&gt; x.Name == tag)
                  .Select(x =&gt; new QuestionTag { Tag = new Tag { Name = x.Name } })
                  .FirstOrDefault();
  
              if (tagExists == null)
              {
                  var newTag = new QuestionTag() { Tag = new Tag() { Name = tag } };
                  _context.QuestionTags.Add(newTag);
                  questionTags.Add(newTag);
  
                  anyNewTags = true;
              }else
              {
  
                  questionTags.Add(tagExists);
              }
  
          }
              if (anyNewTags) _context.SaveChanges();
          return questionTags;
      }
  </code></pre>
  
  <p>But Instead, I get this Error when I try to parse in new Tags:
  <strong>InvalidOperationException: The property 'QuestionID' on entity type 'QuestionTag' has a temporary value. Either set a permanent value explicitly or ensure that the database is configured to generate values for this property.</strong></p>