title: delete item from main list if its empty in C# Entity
body: <p>In this code I check if Unit stock is empty for the same product Id which I selected, then I can delete product, but if so, I also want to delete Product Group for all products that have the same group Id after ensuring they all are empty. What should I do? </p>
  
  <p><a href="https://i.stack.imgur.com/KHqDA.png" rel="nofollow noreferrer">here are my model classes</a></p>
  
  <pre><code>public int Get(int? id)
  {
      JalkahoitolaEntities entities = new JalkahoitolaEntities();
      List&lt;int?&gt; items = (from o in entities.Recieved_ammounts
                          where o.ProductId == id
                          select o.UnitStock).ToList();
  
      if (items.Sum() == 0 || items.Sum() == null)
      {
          Product ProductToBeRemoved = (from o in entities.Products
                                          where o.ProductId == id
                                          select o).First();
          entities.Products.Remove(ProductToBeRemoved);
          entities.SaveChanges();
      }
  
      entities.Dispose();
      return 1;
  }
  </code></pre>