title: How do I prevent a temporary value being assigned when editing a record with EntityFramework?
body: <p>I've created an Edit page for a record, when saving, I get the following error:</p>
  
  <p>The property 'Id' on entity type 'LoadTable' has a temporary value while attempting to change the entity's state to 'Modified'. Either set a permanent value explicitly or ensure that the database is configured to generate values for this property.</p>
  
  <p>I think it may be being assigned a temporary value rather than using the existing one.</p>
  
  <p>From my Edit.cs:</p>
  
  <pre><code>[BindProperty]
  public LoadTable LoadTable { get; set; }
  
  public async Task&lt;IActionResult&gt; OnGetAsync(Guid id)
  {
         if (id == null)
         {
              return NotFound();
         }
         LoadTable = await _context.LoadTable.FirstOrDefaultAsync(m =&gt; m.Id == id);
  
         if (LoadTable == null)
         {
              return NotFound();
         }
         return Page();
  }
  
  public async Task&lt;IActionResult&gt; OnPostAsync()
  {
         if (!ModelState.IsValid)
         {
              return Page();
         }
  
         _context.Attach(LoadTable).State = EntityState.Modified;
  
         try
         {
              await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
              if (!LoadTableExists(LoadTable.Id))
              {
                   return NotFound();
              }
              else
              {
                  throw;
              }
          }
      return RedirectToPage("./Index");
  }
  
  private bool LoadTableExists(Guid id)
  {
      return _context.LoadTable.Any(e =&gt; e.Id == id);
  }
  </code></pre>
  
  <p>From context:</p>
  
  <pre><code>
  entity.Property(e =&gt; e.Id).HasDefaultValueSql("(newid())");
  </code></pre>
  
  <p>From Model:</p>
  
  <pre><code>public partial class LoadTable
  {
      public Guid Id { get; set; }
  }
  </code></pre>