Although I'd probably create fields through the UI and export using the Features module (because I'm lazy), if you feel like adding fields to an entity programmatically, you might find http://drupal.org/node/1228878 helpful. That page actually covers:
With Drupal 7's support for Field API, even the die-hard opponents of old-style CCK will find themselves using fields, and (hopefully) entities. But...how do you run a query efficiently on a field which could have multiple values?
The answer lies in EntityFieldQuery. Here are some examples of how it can be used:
$query = new EntityFieldQuery();