title: How can I add a check constraint for JSON in Entity Framework?
body: <p>Adding a <code>JSON CHECK CONSTRAINT</code>for a table field with </p>
  
  <pre><code>ALTER TABLE [dbo].[Data]  
     ADD CONSTRAINT [JsonData must be formatted as JSON] 
     CHECK  (IsJson([JsonData]) &gt; 0)
  </code></pre>
  
  <p>works fine, but I want to make it work for Code First.</p>
  
  <p>I have tried the <code>Reverse Engineering Code First</code>, but it does not help me with this problem. Executing a Sql Command with the same code <code>(Seed() method)</code> works very well, but this is not one of the solutions I would like to use:</p>
  
  <pre><code>protected override void Seed(MyContext context)
  {
      context
      .Database
      .ExecuteSqlCommand(
          "ALTER TABLE [dbo].[Data]  
              ADD CONSTRAINT [JsonData must be formatted as JSON] 
              CHECK  (IsJson([JsonData]) &gt; 0)");
  }
  </code></pre>
  
  <p>Is there any other way I can add a <code>JSON Check Constraint</code> from Code First? </p>