title: "Adding a child row to parent's child collection" v.s. "adding a child to datacontext's child collection"
body: <p><img src="https://i.stack.imgur.com/2A1D2.png" alt="alt text"></p>
  
  <p>I will compare 2 scenarios to add Rsvp rows. Which one do you prefer in production?</p>
  
  <hr>
  
  <p><strong>METHOD 1: Adding a new Rsvp object to datacontext's Rsvp collection</strong></p>
  
  <pre><code>Rsvp r = new Rsvp();
  r.AttendeeName = "xport";
  
  r.DinnerId = 1;//there will be an exception if it is set to a Dinnner object that does not exist.
  
  entities.Rsvps.AddObject(r);
  
  entities.SaveChanges();
  </code></pre>
  
  <blockquote>
    <p>We will get an exception if we attempt to set DinnerId to a Dinner object that does not exist. This behavior is consistent and straightforward.</p>
  </blockquote>
  
  <hr>
  
  <p><strong>METHOD 2: Adding a new Rsvp object to a Dinner object's Rsvps properties</strong></p>
  
  <pre><code>Rsvp r = new Rsvp();
  r.AttendeeName = "xport";
  
  r.DinnerId = 10000;//this Dinner does not exist!
  
  Dinner d = entities.Dinners.First(x =&gt; x.DinnerId == 1);
  
  d.Rsvps.Add(r);
  
  entities.SaveChanges(); 
  </code></pre>
  
  <blockquote>
    <p>The foreign key property DinnerId of a Rsvp object can be set to any number. When this Rsvp object is added to a Dinner object's Rsvps collection, the DinnerId will be overriden silently. Example above shows DinnerId is set to 10000 which is an Id of  an Dinner object that does not exist. Is it an unavoidable behavior?</p>
  </blockquote>