title: SQL Server CE database and ADO.Net Entity Framework - data not saving
body: <p>I have a SQL Server CE database file and I have ADO.NET Entity Framework object named <code>History</code>. I perform the following to get the latest ID:</p>
  
  <pre><code>var historyid = (from id in db.Histories // Get the current highest history Id
                  select (Int32?)(id.Id)).Max();
  
  HistoryID = Convert.ToInt32(historyid);
  
  if (HistoryID == 0) // No current record exists
  {
      HistoryID = 1; // Set the starter history Id
  }
  </code></pre>
  
  <p>(Not the best way, but it is just to test).</p>
  
  <p>This works well and returns the correct value (If I manually enter an ID of 1, it returns 1, same with 2 etc..)</p>
  
  <p>The issue is with the following code:</p>
  
  <pre><code>History history = new History();
  history.Id = 1;
  history.SoftwareInstalled = "test";
  
  db.AddToHistories(history);
  db.SaveChanges();
  </code></pre>
  
  <p>The above works and runs through fine, but the changes are not saved to the database! Why is this? </p>
  
  <p>Here is my db variable: <code>dbDeSluggerEntities db = new dbDeSluggerEntities();</code></p>
  
  <p>Thanks.</p>
  
  <p>Edit: Here is an update: I noticed when I run the program and debug it, it shows that a history has been created and inserted and also gives an error of the primary key already existing, this happens each time I run the application (over and over). However, when I go to server explorer and right click the db and select 'Show Table Data' it shows no data.. When the program is run again, there is no primary key error or history's showing in the debug!</p>