title: C# Unable to determine the principal end of the relationship
body: <pre><code>foreach (var item in order.MyFiles)
  {
     var newFile = adapter.db.File.CreateObject();
  
     newFile.Name = item.FileName;
  
     adapter.db.File.AddObject(newFile);
  
     adapter.db.SaveChanges();
  
     item.MyFile.Add(new MyFile { FileID = newFile.FileID });
  
     adapter.db.SaveChanges();
  }
  
  foreach (var item in tempFilesList)
  {
      adapter.db.DeleteObject(item);
  }
  
  adapter.db.SaveChanges();
  </code></pre>
  
  <p>That code duplicates rows in the <code>MyFile</code> table, e.g if the loop iterates 3 times I see 6 rows (3 x 2*<code>adapter.db.SaveChanges()</code> ???)</p>
  
  <p>But, if I just have only one <code>adapter.db.SaveChanges();</code> (that last one) I get the error</p>
  
  <p><strong>Unable to determine the principal end of the 'my_dbModel.FK_MyFile_File' relationship. Multiple added entities may have the same primary key.</strong></p>
  
  <p>I suppose it is caused that in that case it doesn't commit the <code>adapter.db.File.AddObject(newFile);</code> items before assinging them to the <code>item.MyFile.Add(new MyFile { FileID = newFile.FileID });</code> But I can be wrong, any ideas how to fix it?</p>