When I want to fetch an entity, I normally have a method that uses a query.
This method will always query the database and you will have an up-to-date entity.
But if you need better performance perhaps GetObjectByKey() is a better option.
This method will check the cache first and returns the entity when it has been loaded already.
When it’s not in the cache, it would still query the database.
You need to supply an EntityKey(string qualifiedEntitySetName, string keyName, object keyValue)
I’ve made a generic method which automatically determines the entitySetName:
here’s an example of a call:
ps: I have hardcoded the keyName, because all my tables have an “ID” primary key.
When this is not the case, check out the CreateEntityKey method