title: How to move records from one table to another in linq
body: <p>I have a ProductLevel table in an SQL database. It contains the products for a store. I want to copy these records into a ProductLevelDaily table at the time the user logs onto the hand held device in the morning.</p>
  
  <p>As they scan items the bool goes from false to true so at anytime they can see what items are left to scan/check.</p>
  
  <p>From the mobile device I pass the siteID and date to the server:</p>
  
  <pre><code>int userID = int.Parse(oWebRequest.requestData[5]); and a few other things
  
  IEnumerable&lt;dProductLevelDaily&gt; plditems 
           = DSOLDAL.CheckProductDailyLevelbySiteCount(siteID, currentDate);
  </code></pre>
  
  <p>This checks if there are any records already moved into this table for this store. Being the first time this table should be empty or contain no records for this store on this date.</p>
  
  <pre><code>if (plditems.Count() == 0) // is 0
  {
      IEnumerable&lt;dProductLevel&gt; ppitems = DSOLDAL.GetProductsbySite(siteID);
  
      // this gets the products for this store 
      if (ppitems.Count() &gt; 0)
      {
          dProduct pi = new dProduct();
  
          foreach (dProductLevel pl in ppitems)
          {
              // get the product
              pi = DSOLDAL.getProductByID(pl.productID, companyID);
  
              dProductLevelDaily pld = new dProductLevelDaily();
  
              pld.guid = Guid.NewGuid();
              pld.siteID = siteID;
              pld.statusID = 1;
              pld.companyID = companyID;
              pld.counted = false;
              pld.createDate = DateTime.Now;
              pld.createUser = userID;
              pld.productID = pl.productID;
              pld.name = "1000"; //  pi.name;
              pld.description = "desc"; // pi.description;
  
              DSOLDAL.insertProductLevelDailyBySite(pld);
          }
      }
  }
  </code></pre>
  
  <p>On the PDA the weberequest response returns NULL</p>
  
  <p>I can't see what the problem is and why it wont work.</p>
  
  <p>The insert is in DSOLDAL:</p>
  
  <pre><code>public static void insertProductLevelDailyBySite(dProductLevelDaily pld)
  {
      dSOLDataContext dc = new dSOLDataContext();
  
      try
      {
          dc.dProductLevelDailies.InsertOnSubmit(pld);
          // dProductLevelDailies.Attach(pld, true);
          dc.SubmitChanges();
      }
      catch (Exception exc)
      {
          throw new Exception(getExceptionMessage(exc.Message));
      }
      finally
      {
          dc = null;
      }
  }
  </code></pre>
  
  <p>This code works until I put the foreach loop inside with the insert</p>
  
  <pre><code>IEnumerable&lt;dProductLevelDaily&gt; plditems
             = DSOLDAL.CheckProductDailyLevelbySiteCount(siteID, s);
  
  if (plditems.Count() == 0) // plditems.Count() &lt; 0) 
  {
      IEnumerable&lt;dProductLevel&gt; ppitems = DSOLDAL.GetProductsbySite(siteID);
      if (ppitems.Count() &gt; 0)
      {
  
          oWebResponse.count = ppitems.Count().ToString();
          oWebResponse.status = "OK";
      }
      else
      {
          oWebResponse.count = ppitems.Count().ToString();
          oWebResponse.status = "OK";
  
      }
  }
  else
  {
      oWebResponse.count = "2"; //  plditems.Count().ToString();
      oWebResponse.status = "OK";
  }
  </code></pre>