title: EF 5 Code first Entities FirstOrDefault method returns null
body: <p>This is an example based on Programming Code First EF.</p>
  
  <p>Please look at the below classes. When the PersonRepository calls in instantiated and InsertOrUpdate method is called Null value is returned. As of i know IQuariable's FitstOrDefault should not return Null. </p>
  
  <p>What is wrong here. Thanks for the help</p>
  
  <pre><code>    public class Person
  {
  
      public int PersonId { get; set; }
      public int SocialSecurityNumber { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      //public int MyProperty { get; set; }
      public List&lt;Lodging&gt; PrimaryContactFor { get; set; }
      public List&lt;Lodging&gt; SecondaryContactFor { get; set; }
  
      public PersonPhoto Photo { get; set; }
  }
  </code></pre>
  
  <p>Photo Class</p>
  
  <pre><code>    public class PersonPhoto
  {
      public int PersonID { get; set; }
      public byte[] Photo { get; set; }
      public string Caption { get; set; }
      public Person PhotoOf { get; set; }
  }
  </code></pre>
  
  <p>DBContext Class</p>
  
  <pre><code>    public class DomainContext:DbContext,IDisposable
  {
      public DomainContext(string connectionString):base(connectionString)
      { 
      }
  
      public DbSet&lt;Person&gt; People { get; set; }
  
      protected override void Dispose(bool disposing)
      {
          base.Dispose(disposing);
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
  
          modelBuilder.Entity&lt;PersonPhoto&gt;()
              .HasKey(p =&gt; p.PersonID);
  
          modelBuilder.Entity&lt;PersonPhoto&gt;()
              .HasRequired(p =&gt; p.PhotoOf)
              .WithRequiredDependent(p =&gt; p.Photo);
  
  
      }
  }
  </code></pre>
  
  <p>Repository Class </p>
  
  <pre><code>        public class PersonRepository
      {
  
          public PersonRepository()
          {
          }
          public void  InsertOrUpdate()
          {
            using(        DomainContext ctx = new DomainContext())
            {
              var person= ctx.People.Include("Photo").FirstOrDefault();
              person.FirstName="Pnikey";
              if(person.Photo==null)
              {
                  person.Photo= new PersonPhoto{Photo=new byte[]{0}};
              }
              ctx.SaveChanges();
            }
          }
      }
  </code></pre>