title: Prevent related records being updated in Entity Framework
body: <p>I have an entity (Skill) which has a relationship to another entity (Game):</p>
  <pre><code>    public class Skill
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      [Key]
      public Guid Id { get; set; }
      public virtual Game Game { get; set; }
      public virtual IdentityUser TeamMember { get; set; }
      public int SkillPoints1 { get; set; }
      public int SkillPoints2 { get; set; }
      public int SkillPoints3 { get; set; }
      public int SkillPoints4 { get; set; }
      public int SkillPoints5 { get; set; }
      public bool Spectator { get; set; }
      public Skillset SelectedSkillNumber { get; set; }
  }
  </code></pre>
  <p>The Game entity also has related entities:</p>
  <pre><code>    public class Game
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      [Key]
      public Guid Id { get; set; }
      public string GameTitle { set; get; }
      public DateTime Created { get; set; }
      public GameState GameState { get; set; }
      public virtual Team GameTeamMembers { get; set; }
      public virtual IdentityUser GameOwner { get; set; }
      public virtual ICollection&lt;Backlog&gt; ProductBacklog { get; set; }
  </code></pre>
  <p>At some point, I'm loading in the &quot;Skills&quot; for a particular Game, so I have to include the game record in order to return the Skill records:</p>
  <pre><code>List&lt;Skill&gt; allSkillsets = _context.Skills.Include(x =&gt; x.Game).Where(x =&gt; x.Game.Id == gameId).Include(x =&gt; x.TeamMember).ToList();
  </code></pre>
  <p>However, when I'm looping through these records to update some of the properties, EF tries to update the &quot;Game&quot; record as well:</p>
  <pre><code>                foreach (Skill player in allSkillsets)
              {
                  try
              {
                  player.SkillPoints1 = player.SelectedSkillNumber == Skillset.Skill1 ? 5 : boost_skillset1_by + 1;
                  player.SkillPoints2 = player.SelectedSkillNumber == Skillset.Skill2 ? 5 : boost_skillset2_by + 1;
                  player.SkillPoints3 = player.SelectedSkillNumber == Skillset.Skill3 ? 5 : boost_skillset3_by + 1;
                  player.SkillPoints4 = player.SelectedSkillNumber == Skillset.Skill4 ? 5 : boost_skillset4_by + 1;
                  player.SkillPoints5 = player.SelectedSkillNumber == Skillset.Skill5 ? 5 : boost_skillset5_by + 1;
  
                  //_context.Entry(player.Game).State = EntityState.Detached;
                  _context.Entry(player.Game).State = EntityState.Unchanged;
  
                  _context.Skills.Attach(player);
                  _context.Entry(player).Property(x =&gt; x.SkillPoints1).IsModified = true;
                  _context.Entry(player).Property(x =&gt; x.SkillPoints2).IsModified = true;
                  _context.Entry(player).Property(x =&gt; x.SkillPoints3).IsModified = true;
                  _context.Entry(player).Property(x =&gt; x.SkillPoints4).IsModified = true;
                  _context.Entry(player).Property(x =&gt; x.SkillPoints5).IsModified = true;
                  await _context.SaveChangesAsync();
              }
              catch (DbUpdateConcurrencyException)
              {
                  _logger.LogErrorWithObject(&quot;Could not write backlog item to database&quot;, &quot;UpdatePlayerSkills&quot;, player);
                  throw;
              }
  </code></pre>
  <p>Because the &quot;Game&quot; entity doesn't have all of it's related entities loaded in (e.g. ProductBacklog), the update wipes out all of these records.
  Is there a way I can just update the 5 properties in the Skill record, without also updating it's related Game record?</p>
  <p>I've also tried setting Game to null, but then this removes the Id in the foreign key column</p>