title: Delete records from relationship tables in entity framework
body: <p>I have created following entity classess for my db tables </p>
  
  <pre><code> public class Jewelry
      {
          #region Properties
          public Jewelry_Items jewelryItems { get; set; }
          public Jewelry_Addnl_Details jewelryAddnlDetails { get; set; }
          #endregion
      }
  
      public class Jewelry_Items
      {
  
          #region Properties
          [Key]
          public int JewelryID { get; set; }
          public int GeneralInfoID { get; set; }
          public string Style { get; set; }
          public string JewelryType { get; set; }
          public string JewelryDesc { get; set; }
          public string AddnlDetails { get; set; }
          public string OtherDetails { get; set; }
          public string RingCut { get; set; }
          public string ModelNumber { get; set; }
          public string CreatedBy { get; set; }
          public DateTime CreatedDate { get; set; }
          public string LastModifiedBy { get; set; }
          public DateTime LastModifiedDate { get; set; }
          #endregion
      }
  
      public class Jewelry_Addnl_Details
      {
          #region Properties
          [Key]
          public int ID { get; set; }
          public int JewelryID { get; set; }
          public string IsCompletedDesc { get; set; }
          public string AppraisalDate { get; set; }
          public int ReplacementValue { get; set; }
          public string UseOnBehalf { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Relationship { get; set; }
          #endregion
      }
  </code></pre>
  
  <p>JewelryId has a FK relationship between two tables. I want to delete the record from two tables so I did following . Is there any better way of doing this?</p>
  
  <pre><code> using (var db = new Context())
              {
                  var jewelryItem = db.JewelryItemsList.SingleOrDefault(x =&gt; x.JewelryID == jewelryID);
                  var jewelryAddnlDetail = db.JewelryAddnlDetailsList.SingleOrDefault (x =&gt; x.JewelryID == jewelryID);
                  if (jewelryAddnlDetail != null)
                  {
                      db.JewelryAddnlDetailsList.Remove(jewelryAddnlDetail);
                  }
  
                  if (jewelryItem != null)
                  {
                      db.JewelryItemsList.Remove(jewelryItem);
                  }
  
                  db.SaveChanges();
                  isSuccess = true;
              }
  </code></pre>
  
  <p>Update : </p>
  
  <p>New code </p>
  
  <pre><code> public class RLI_Jewelry_Items
      {
  
          #region Properties
          [Key]
          public int JewelryID { get; set; }
  
          [ForeignKey("GeneralInfoID")]
          public virtual RLI_Insured_GeneralInfo RLI_Insured_GeneralInfo { get; set; }
  
          public int GeneralInfoID { get; set; }
  
          public string Style { get; set; }
          public string JewelryType { get; set; }
          public string JewelryDesc { get; set; }
          public string AddnlDetails { get; set; }
          public string OtherDetails { get; set; }
          public string RingCut { get; set; }
          public string ModelNumber { get; set; }
          public string CreatedBy { get; set; }
          public DateTime CreatedDate { get; set; }
          public string LastModifiedBy { get; set; }
          public DateTime LastModifiedDate { get; set; }
          #endregion
      }
  
      public class RLI_Jewelry_Addnl_Details
      {
          #region Properties
          [Key]
          public int ID { get; set; }
  
          [Required]
          [ForeignKey("JewelryID")]
          public virtual RLI_Jewelry_Items RLI_Jewelry_Items { get; set; }
  
          [Required]
          public int JewelryID { get; set; }
  
          public string IsCompletedDesc { get; set; }
          public string AppraisalDate { get; set; }
          public int ReplacementValue { get; set; }
          public string UseOnBehalf { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Relationship { get; set; }
          #endregion
      }
  </code></pre>