I am using LINQ to SQL with Sql Server Compact Edition 3.5 and VS2008.
I have a very simple table (tokens) with the primary key uniqueidentifier (TokenID) and two other fields with the ability to drop (UsedBy and UsedOn). I am trying to use LINQ to insert new rows into a table, but for some reason they are not saved.
Here is my code:
var connectionstring = "Data Source=|DataDirectory|\\MyData.sdf";
MyData db = new MyData(connectionstring) { Log = Console.Out };
Tokens token = new Tokens { TokenID = Guid.NewGuid() };
db.Tokens.InsertOnSubmit(token);
db.SubmitChanges();
var tokens = from t in db.Tokens
select t;
foreach (var t in tokens)
{
Debug.Print(t.TokenID.ToString());
}
If I uncomment db.GetChangeSet (); I see a pending insert, and when I repeat and print them into a debug widow, the number of tokens grows every time. But if I query the table in VS (via Show Table Data), is it empty? Looking at data like this also discards tokens returned by LINQ to their original state.
I am sure that I am making some simple mistake, but I do not see this. Any ideas?