diff --git a/entityreference.migrate.inc b/entityreference.migrate.inc
index 35737b5..a2c5e0c 100644
--- a/entityreference.migrate.inc
+++ b/entityreference.migrate.inc
@@ -30,4 +30,124 @@ class MigrateEntityReferenceFieldHandler extends MigrateSimpleFieldHandler {
 
     $this->registerTypes(array('entityreference'));
   }
+
+  /**
+   * {@inherit_doc}
+   */
+  public function prepare($entity, array $field_info, array $instance, array $values) {
+    if (isset($values['arguments'])) {
+      $arguments = $values['arguments'];
+      unset($values['arguments']);
+    }
+    else {
+      $arguments = array();
+    }
+    if (empty($values[0])) {
+      $values = array();
+    }
+
+    $ids = array();
+    if (isset($arguments['source_type']) && $arguments['source_type'] == 'name') {
+      $entity_type = $instance['entity_type'];
+      $target_type = $field_info['settings']['target_type'];
+
+      // Use the query for the selection handler for this field.
+      $handler = entityreference_get_selection_handler(
+        $field_info,
+        $instance,
+        $entity_type,
+        $entity
+      );
+
+      $results = $handler->getReferencableEntities($values, 'IN');
+      // Cleanup results from target bundles.
+      $results = array_values($results);
+      // Create an array of entity label to id.
+      // We assume only one target_bundle.
+      $entity_labels = !empty($results[0])
+        ? array_flip($results[0])
+        : array();
+
+      // If we're ignoring case, change both the matched term name keys and the
+      // source values to lowercase.
+      if (isset($arguments['ignore_case']) && $arguments['ignore_case']) {
+        $ignore_case = TRUE;
+        $entity_labels = array_change_key_case($entity_labels);
+        foreach ($values as $value) {
+          $lower_values[$value] = strtolower($value);
+        }
+      }
+      else {
+        $ignore_case = FALSE;
+      }
+
+      foreach ($values as $value) {
+        if (isset($entity_labels[$value])) {
+          // If we found an id for the label, take it.
+          $ids[] = $entity_labels[$value];
+        }
+        elseif ($ignore_case && isset($entity_labels[$lower_values[$value]])) {
+          $ids[] = $entity_labels[$lower_values[$value]];
+        }
+        elseif (!empty($arguments['create_entity'])) {
+          // No entity is found for the source value: create one.
+          $info = entity_get_info($target_type);
+          $create_values = array(
+            $info['entity keys']['bundle'] => $arguments['create_entity_bundle'],
+            $info['entity keys']['label'] => $value,
+          );
+          $new_entity = entity_create($target_type, $create_values);
+
+          if (!is_null($new_entity)) {
+            // Special fallback for taxonomy term.
+            if ($target_type == 'taxonomy_term') {
+              $names = taxonomy_vocabulary_get_names();
+              $new_entity->vid = $names[$new_entity->vocabulary_machine_name]->vid;
+              // This term is being created with no fields,
+              // but we should still call field_attach_validate() before saving,
+              // as that invokes hook_field_attach_validate().
+              MigrateDestinationEntity::fieldAttachValidate('taxonomy_term', $new_entity);
+            }
+            // If we have a validate new entity, save it and add its ID to the migration values.
+            entity_save($target_type, $new_entity);
+            list ($new_entity_id) = entity_extract_ids($target_type, $new_entity);
+            $ids[] = $new_entity_id;
+          }
+          else {
+            // If we don't, log a warning.
+            $migration = Migration::currentMigration();
+            $migration->saveMessage(t("Creation of new referenced entity failed for source value '@value'.",
+              array('@value' => $value)), MigrationBase::MESSAGE_INFORMATIONAL);
+          }
+        }
+        else {
+          // No entity is found for the source value and none is to be created:
+          // warn that data has not been imported.
+          $migration = Migration::currentMigration();
+          $migration->saveMessage(t("No matching entity found for source value '@value'.",
+            array('@value' => $value)), MigrationBase::MESSAGE_INFORMATIONAL);
+        }
+      }
+    }
+    else {
+      // Nothing to do. We have ids already.
+      $ids = $values;
+    }
+
+    // Setup the Field API array for saving.
+    $language = $this->getFieldLanguage($entity, $field_info, $arguments);
+    $delta = 0;
+    foreach ($ids as $id) {
+      if (is_array($language)) {
+        $current_language = $language[$delta];
+      }
+      else {
+        $current_language = $language;
+      }
+      $return[$current_language][] = array($this->fieldValueKey => $id);
+      $delta++;
+    }
+    return isset($return) ? $return : NULL;
+  }
+
 }
