If you know the type of the entity you're retrieving, you can use the Set
method on DbContext to get a DbSet
, and the Find
method on DbSet
to get an entity by its key(s).
var dbSet = dbContext.Set<TestTable>();
var entity = dbSet.Find(EntityKey.EntityKeyValues[0].Value);
The Find
method knows how to turn use the key value to get an entity; in fact, the signature is Find(params object[])
so you can pass in multiple key values if your table has a composite key (as long as they're in the right order).