title: How to set unique constraint for nullable column with entity framework?
body: <p>I am using entity framework version 6 and i have a model like this:</p>
  
  <pre><code>public class SizeCount
      {
          public int Count { get; set; }
          public Size Size { get; set; }
          public long? SizeId { get; set; }
          public Color Color { get; set; }
          public long? ColorId { get; set; }
          public Product Product { get; set; }
          public long ProductId { get; set; }
      }
  </code></pre>
  
  <p>I want to prevent from <code>ColorId</code> and <code>SizeId</code> both be null and i want to <code>ProductId</code>,<code>ColorId</code>,<code>SizeId</code> be unique.
  some example record: </p>
  
  <pre><code>ProductId SizeId ColorId
  1         null   1       &gt; allow
  1         null   1       &gt; not allow
  1         1      null    &gt; not allow
  2         1      null    &gt; allow
  2         null   1       &gt; not allow
  </code></pre>
  
  <p><code>SizeId</code> or <code>ColorId</code> can be null.
  Is there any attribute that can help me in the entity framework or i should check it manually?</p>