I insert a new object into the LINC-to-SQL DataContext without calling the SubmitChanges () function:
MyDataContext db = new MyDataContext();
MyObject newObject = new MyObject()
{
Id = 1,
Name = "MyName"
};
db.MyObjects.InsertOnSubmit(newObject);
Now elsewhere in my code I want to get this new object, although it is not already in the database. Therefore, I am passing the same instance of the DataContext because I believe that the new object is cached inside it. And now I want to get it. But this does not work:
MyObject newObject = db.MyObjects.Where(o => o.Id == 1).SingleOrDefault();
How can I do what I want? Is it possible?
source
share