To query the local object context
When faced with the dilemma that what if I wanted to insert something and before I actually saved the changes into a persistent storage (database) by calling SaveAllChanges() method on the data context, I wanted to do a select, and also I wanted to make sure that this select is done on the just inserted objects, what should I be doing? Well generally we write a generic method that gets all the records for a generic object. it looks like this: IQueryable<T> result = null; string type = typeof(T).Name; //ObjectQuery query = entities.CreateQuery<T>(type); ObjectQuery query = Context.CreateQuery<T>(type); result = ( IQueryable<T>)query; return result; This will only query into the database
Here is the original post:
To query the local object context


