Querying the entity set directly always queries the database. Querying
Local (or the
ObjectContext equivalent) always queries the entities in memory. But what if you want to do both? If an entity has been loaded, you want to work with the version in memory. If it hasn’t been loaded, you want to load it. Seems perfectly reasonable to me. Again, both the
ObjectContext APIs provide a means to do this, and the
DbContext version is a bit easier to use. But this time the difference isn’t quite so striking.
With the the
DbSet<T>.Find() method, the only (possibly) tricky bit is knowing the primary key of the entity you want.
DbSet<T>.Find() method will only make a trip to the database if it can’t find the primary key ...