I insert a new object into LINQ-to-SQL DataContext without calling SubmitChanges() yet:
MyDataContext db = new MyDataContext();
MyObject newObject = new MyObject()
{
Id = 1,
Name = "MyName"
};
db.MyObjects.InsertOnSubmit(newObject);
Now in another place in my code I want to retrieve this new object, even though it is not in the database yet. So I pass the same DataContext instance there, because I believe that the new object is cached inside it. And now I want to retrieve it. But this doesn't work:
MyObject newObject = db.MyObjects.Where(o => o.Id == 1).SingleOrDefault();
How can I do what I want? Is that possible?