I am using LINQ to SQL with Sql Server Compact Edition 3.5 and VS2008.
I have a very simple table (Tokens) with a uniqueidentifier primary key (TokenID) and two other nullable fields (UsedBy and UsedOn). I am trying to use LINQ to insert new rows into the table but for some reason they are not persisting.
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.GetChangeSet();
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 can see the pending insert and when I iterate and print them to the debug widow the # of tokens grows each time. But if I query the table in VS (via Show Table Data) it is empty? Viewing the data like this also "resets" the tokens returned by LINQ their original state.
I am pretty sure I am making some simple mistake, but I can't see it. Any ideas?