title: Stored procedure returns complex type, I use AutoMapper to map it to my model but foreign key objects do not get set
body: <p>I use AutoMapper to map from my DataLayer(EF6 DbFirst AutoGenerated layer) to my ModelLayer(Pocos/Dtos). One thing I am confused about is when using stored procedures they return a complex object such as Customer_GetCustomers_Result so I have to map this to my CustomerPoco with AutoMapper and I lose foreign key object properties such as Customer.Address since they are not in my complex type.</p>
  
  <p>Here is an example of my CustomerPoco:</p>
  
  <pre><code>public class Customer
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string Phone { get; set; }
      public string Fax { get; set; }
      public string Website { get; set; }
      public int AddressId { get; set; }
  
      // THESE END UP NOT GETTING SET
      public List&lt;CustomerContact&gt; Contacts { get; set; }
      public Address Address { get; set; }
  }
  </code></pre>
  
  <p>In my GetCustomers stored procedure lets say I do something simple like: SELECT * FROM CUSTOMER. It returns a complex object context.Customer_GetCustomers_Result. Then I have to map this complex object to my CustomerPoco. The Contacts and Address do not get set. How should I go about this?</p>
  
  <p>Here are my mappings for Customer:</p>
  
  <pre><code>    CreateMap&lt;Customer, Model.Customer&gt;()
          .ForMember(dest =&gt; dest.Contacts, opt =&gt; opt.MapFrom(src =&gt; src.CustomerContacts));
  
      CreateMap&lt;Customer_GetCustomers_Result, Model.Customer&gt;();
  </code></pre>
  
  <p>This actually might have been a bad question. I believe if I really want to use stored procedures to return my lists I will need to do joins and actually return the properties of Address in my select such as... a.Address1, a.Address2, etc. Then is there a way to map them to Model.Customer.Address from here even though they are all split out into individual properties?</p>