title: Nullable Properties in EF Code First?
body: <p>I hope everyone remembers the Northwind database. As it has an Employee table which has a self-reference to itself. The Foreign Key is named 'ReportTo' or something like that which in turn is a Nullable field.</p>
  
  <p>I am trying to implement such a table for a project in hand using EF Code First plus MVC3. The scenario is that: There is a Man class from which the User is derived. The mentioned field 'ReportTo' is set on the latter class (User). Here is the POCO:</p>
  
  <pre><code>[LocalizedAttribute("ReportTo")]
      public long ReportsTo { get; set; }
      [ForeignKey("ReportsTo")]
      public virtual IList&lt;User&gt; ReportsChild { get; set; }
  </code></pre>
  
  <p><em>But EF generated this field as 'Not Null' in the Database.</em> I have tried to use <code>?</code> exactly after <code>IList&lt;User&gt;</code>, which looks like <code>IList&lt;User&gt;?</code> that generates an error. I have also tried to define it as fluent API as:</p>
  
  <p><code>modelBuilder.Entity&lt;User&gt;().Property(s =&gt; s.ReportsChild).IsOptional();</code></p>
  
  <p>But both above ways give me this error:</p>
  
  <blockquote>
    <p>The type 'System.Collections.Generic.IList' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'</p>
  </blockquote>
  
  <p>I've surfed the web but I could just find similar solutions as what I've done already.</p>
  
  <p>What might be the reason?
  If I change <code>IList&lt;User&gt;</code> into <code>User</code>, would it still work correctly as the Foreign key?
  How can I get ride of this error?</p>