title: Entity Framework Core 2 (Code First) updating value not working
body: <p>I've been struggling with changing values in a database for a week and can't find out what I'm doing wrong. I managed to create tables, to add and delete entities but I can't change a value inside an entity.</p>
  
  <p>The error I get is: <em>The property 'Rating' on entity type 'Generation' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity whith an identifying foreign key first delete the dependent and invoke 'SaveChanges' then associate the dependent with the new principal.</em></p>
  
  <p>(I'm not used to the term <em>principal</em> but I think it is the entity which has the unique Key. I not used to the term <em>dependent</em>  either in a database context but I think it is the entity in another table which has a link to the <em>principal</em>)</p>
  
  <p>FYI: I'm using Microsoft.AspNetCore.All 2.0.0, Microsoft.EntityFrameworkCore 2.0.0 and Npgsql.EntityFrameworkCore.PostgreSQL 2.0.0</p>
  
  <p>I'm sure this error message tries to tell me the solution but as far as I know there is nothing dependent on <em>Rating</em> and it's not a key. For context here are the two classes I'm using for tables in the database:</p>
  
  <pre><code>[Table("Generation")]
  public class Generation
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int GenerationId { get; set; }
  
      [Required]
      [MaxLength(100)]
      public string DNA { get; set; }
      //[Editable(true)]
      public double Rating { get; set; }
  
      public Generation(int ID, string dna, double rate)
      {
          GenerationId = ID;
          DNA = dna;
          Rating = rate;
      }
  
      public Generation()
      {
  
      }
  }
  
  [Table("Device")]
  public class Device
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int DeviceID { get; set; }
  
      //[Required]
      [MaxLength(100)]
      public string Identifier { get; set; }
  
      //[ForeignKey("GenerationId2")] &lt;-- should be changed to GenerationId in the near future
      public int GenerationId2 { get; set; }
      public float WaitingSeconds { get; set; }
  }
  </code></pre>
  
  <p>(It's a database I want to keep on a server for genetic algorithms)</p>
  
  <p>The code I use to change the data is quite simple but causes the error on SaveChanges():</p>
  
  <pre><code>Generation gen = Program.Context.Generation.FirstOrDefault(g =&gt; g.Rating &lt; 0.0);
  if (gen != null)
  {
  gen.Rating = 10.0;
  Debug.Log("DNA: About to save changes");
  Program.Context.SaveChanges();
  }
  </code></pre>
  
  <p>(The generations are created with a negative rating to indicate that that DNA has not been tested yet)</p>
  
  <p>I experimented with different data annotations such as [Editable(true)], [Required] and [ForeignKey] &lt;- which I suppose marks it as dependent on the principal from another class/table.</p>
  
  <p>Could someone help me out to "simply" change some data in a table?</p>
  
  <p>Kind regards!</p>
  
  <p>Cambesa</p>