How to find the entity specific named id?
This should do it (definitely works for all core entities, I don't have any custom entities to play with on my sandbox site I'm afraid):

$type = 'taxonomy_term';

// Get the entity type info
$info = entity_get_info($type);

// Grab the id key
$key = $info['entity keys']['id'];

// $key contains 'tid'


I'm pretty positive this will work across any entity type though, according to hook_entity_info() the id property of entity keys is required:


  Every entity object passed to the Field API must have this property and its value must be numeric.