title: Entity framework Database First & EF Code First get Relation Object By ID
body: <p>in EF Database First  when change ForeignKey(CommodityGroupID) automatic Get CommodityGroup for Commodity object, But in EF Code First(4.3.1) not doing.</p>
  
  <pre><code>public class Commodity  
          {
              public int CommodityID { get; set; }
              public string MadeBy { get; set; }
              public decimal ServiceTimePrice { get; set; }
              public decimal QCPrice { get; set; }
              public int ServicePoint { get; set; }
              public string Note { get; set; }
              public int CommodityGroupID { get; set; }
              [ForeignKey("CommodityGroupID")]
              public virtual CommodityGroup CommodityGroup { get; set; }
      }
      public class CommodityGroup
      { 
          public int CommodityGroupID { get; set; }
          public string CommodityGroupName { get; set; } 
          public virtual ICollection&lt;Commodity&gt; Commodities { get; set; }
  
      }
  </code></pre>
  
  <p>this Property defined in   Edmx file (database first), i Should define this code in ef code first?</p>
  
  <pre><code>[BrowsableAttribute(false)]
  [DataMemberAttribute()]
  public EntityReference&lt;CommodityGroup&gt; CommodityGroupReference
  {
      get
      {
          return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference&lt;CommodityGroup&gt;("GaamRepairModel.FK_Commodity_CommodityGroup", "CommodityGroup");
      }
      set
      {
          if ((value != null))
          {
              ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference&lt;CommodityGroup&gt;("GaamRepairModel.FK_Commodity_CommodityGroup", "CommodityGroup", value);
          }
      }
  }
  </code></pre>