title: How can I add data in foreign key field in Entity Framework?
body: <p>How can I give set foreign key value field in Entity Framework. I have Kartlar entity (related from kartlar table). I need simple save method this field but, RehberID, KAmpanyaId,BirimID is foregin Key....</p>
  
  <pre><code>public static class SatisServicesUpdateTables
  {
      public static void SaveKartlar(int RehberID, int KampanyaID, int BrimID)
      {
          using (GenSatisModuleEntities genSatisKampanyaCtx = new GenSatisModuleEntities())
          {
              Kartlar kartlar = new Kartlar();
              kartlar.RehberReference.EntityKey = new System.Data.EntityKey("genSatisKampanyaCtx.Rehber", "ID", RehberID);
              kartlar.KampanyaReference.EntityKey = new System.Data.EntityKey("genSatisKampanyaCtx.Kampanya", "ID", KampanyaID);
              kartlar.BirimReference.EntityKey = new System.Data.EntityKey("genSatisKampanyaCtx.Birim", "ID", BrimID);
              kartlar.Notlar = "hfhfhfhfhfhfghfghfgfghk";
              genSatisKampanyaCtx.AddToKartlar(kartlar);
              genSatisKampanyaCtx.SaveChanges();
          }
      }
  }
  </code></pre>
  
  <p>But it throws to me : ArgumentException was unhandled by user code</p>
  
  <p><a href="http://www.ressim.net/upload/3548512e.png" rel="nofollow noreferrer">link text</a></p>