title: Programmatically creating LookupAttributeMetadata in Dynamics CRM 2015
body: <p>I am about to migrate a Dynamics CRM 2011 On Premise instance to Dynamics CRM 2015 Online. </p>
  
  <p>I'm using the current Dynamics CRM SDK (current Version 7.1) and have managed to migrate the custom attributes, except the <code>Virtual</code> and <code>Lookup</code> ones, which can't be created via <code>CreateAttributeRequest</code>.</p>
  
  <p>Now next, I need to migrate all the relationships. So far I've been able to get the necessary <code>OneToManyRelationshipMetadata</code> and <code>ManyToManyRelationshipMetadata</code>. However, for <code>OneToManyRelationshipMetadata</code> I need to pass a <code>LookupAttributeMetadata</code> to the <code>CreateAttributeRequest</code>. </p>
  
  <pre><code>OneToManyRelationshipRequest request = new OneToManyRelationshipRequest() 
  {
      Lookup = new LookupAttributeMetadata() 
      {
          SchemaName = "new_topicid",
          DisplayName = new Label("Subject", 1033),
          Description = new Label("Subject Description", 1033)
      },
      OneToManyRelationship = new OneToManyRelationshipMetadata() 
      {
          ReferencedEntity = "subject",
          ReferencedAttribute = "subjectid",
          ReferencingEntity = "customer",
          ReferencingAttribute = "new_topicid"
      }
  }
  </code></pre>
  
  <p>However, I get the exception that attribute <code>new_topicid</code> doesn't exist. That may make sense, since I had to skip it during Attribute creation earlier (since it can't be created through <code>CreateAttributeRequest</code>). </p>
  
  <p>Is there any other way how I can migrate the <code>LookupAttributeMetadata</code> or <code>OneToManyRelationshipMetadata</code>/<code>ManyToManyRelationshipMetadata</code> to Dynamics CRM online? </p>