title: EF code first migrations, DB generated GUID keys
body: <p><strong>The question as a one liner</strong></p>
  <p>How do I get EF to generate as part of a code first migration</p>
  <pre><code>ALTER TABLE [DMS].[Forms] ADD  CONSTRAINT [DF_DMS.Forms_Id]  DEFAULT (newid()) FOR [Id]
  GO
  </code></pre>
  <p><strong>More detail of the problem</strong></p>
  <p>I'm to build out a simple table to store information about forms, as it happens I already have this working for another table in my db but if I show you the code (see below) you'll realise the issue I'm hitting is stranger than it might seem ...</p>
  <p>First the working example entity:</p>
  <pre><code>[Table(&quot;Files&quot;, Schema = &quot;DMS&quot;)]
  public class File
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid Id { get; set; }
      ...
  }
  </code></pre>
  <p>ok, now the not working one ...</p>
  <pre><code>[Table(&quot;Forms&quot;, Schema = &quot;CMS&quot;)]
  public class Form
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid Id { get; set; }
      ...
  }
  </code></pre>
  <p>As stated in the question, I'm using EF code first, so here's the migration code:</p>
  <p>The working one:</p>
  <pre><code>CreateTable(
      &quot;DMS.Files&quot;,
      c =&gt; new
          {
              Id = c.Guid(nullable: false),
              ...
          })
      .PrimaryKey(t =&gt; t.Id)
      ...;
  </code></pre>
  <p>... and the non working one ...</p>
  <pre><code>CreateTable(
      &quot;CMS.Forms&quot;,
      c =&gt; new
          {
              Id = c.Guid(nullable: false),
              ...
          })
      .PrimaryKey(t =&gt; t.Id)
      ...;
  </code></pre>
  <p>So all is good ... then I migrate my db with an &quot;update-database&quot; command and script the two tables ...</p>
  <p>The working one:</p>
  <pre><code>...
  CREATE TABLE [DMS].[Files](
      [Id] [uniqueidentifier] NOT NULL,
      ...
   CONSTRAINT [PK_DMS.Files] PRIMARY KEY CLUSTERED 
  (
      [Id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  
  GO
  
  ALTER TABLE [DMS].[Files] ADD  CONSTRAINT [DF_DMS.Files_Id]  DEFAULT (newid()) FOR [Id]
  GO
  ...
  </code></pre>
  <p>... and the non working one ...</p>
  <pre><code>...
  CREATE TABLE [CMS].[Forms](
      [Id] [uniqueidentifier] NOT NULL,
      ...
   CONSTRAINT [PK_CMS.Forms] PRIMARY KEY CLUSTERED 
  (
      [Id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  
  GO
  ...
  </code></pre>