title: Entity Framework 5 DbUpdateException: Null value for non-nullable member
body: <p>I have some data models:</p>
  
  <pre><code>[DataContract(Name = "artist")]
  public class artist : IEqualityComparer&lt;artist&gt;
  {
      [Key]
      [XmlIgnore]
      [DataMember]
      public int ID { get; set; }
  
      [DataMember]
      [XmlElement(ElementName = "name")]
      public string name { get; set; }
  
      [DataMember]
      [XmlElement(ElementName = "mbid", IsNullable = true)]
      public string mbid { get; set; }
  
      [DataMember]
      [XmlElement(ElementName = "url")]
      public string url { get; set; }
  
      [XmlElement(ElementName = "image", IsNullable = true)]
      public List&lt;string&gt; image { get; set; }
  
      [DataMember(IsRequired=false)]
      [XmlElement(ElementName = "stats", IsNullable = true)]
      public stats stats { get; set; }
  
      public double? match { get; set; }
      public List&lt;tag&gt; tags { get; set; }
      [XmlElement(ElementName = "similar")]
      [DataMember(Name = "similar")]
      public List&lt;artist&gt; similar { get; set; }
  
      [DataMember]
      [XmlElement(ElementName = "bio", IsNullable = true)]
      public wiki bio { get; set; }
  
  
      public bool Equals(artist x, artist y)
      {
          return x.name == y.name;
      }
  
      public int GetHashCode(artist obj)
      {
          return obj.name.GetHashCode();
      }
  }
  </code></pre>
  
  <p>and a complex type:</p>
  
  <pre><code>    [DataContract]
  [ComplexType]
  [XmlRoot(ElementName = "streamable", IsNullable = true)]
  public class stats
  {
      [DataMember(IsRequired = false)]
      public int listeners { get; set; }
  
      [DataMember(IsRequired = false)]
      public int playcount { get; set; }
  }
  </code></pre>
  
  <p>and database inclusion:</p>
  
  <pre><code>[Table("CachedArtistInfo")]
  public class MusicArtists
  {
      [Key]
      public string artistName { get; set; }
      public artist artistInfo { get; set; }
  
      private DateTime _added = default(DateTime);
      [DataMember(IsRequired = true)]
      [Timestamp]
      public DateTime added
      {
          get
          {
              return (_added == default(DateTime)) ? DateTime.Now : _added;
          }
          set { _added = value; }
      }
  }
  </code></pre>
  
  <p>Final step:</p>
  
  <pre><code>        foreach (artist a in id)
          {
              df.CachedArtists.Add(new MusicArtists() { artistName = a.name, artistInfo = a });
              df.SaveChanges();
          }
  </code></pre>
  
  <p>ERROR: 
  ExceptionType
      "System.Data.Entity.Infrastructure.DbUpdateException"
          "Null value for non-nullable member. Member: 'stats'."
  a variable is fully filled and object stats in it.
  what's wrong?</p>
  
  <p><img src="https://i.stack.imgur.com/1TUq2.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/yVPQP.png" alt="enter image description here"></p>